0

I've been following the steps of this very helpful guide on installing junit, but I've run into a problem. I've created this trivial test case as instructed:

import junit.framework.TestCase;

public class TestBasic extends TestCase{
    public void testTrue(){
        assertTrue(true);
    }   
}

When I try to compile it, this happens:

$ javac TestBasic.java 
TestBasic.java:1: error: package junit.framework does not exist
import junit.framework.TestCase;
                      ^
TestBasic.java:3: error: cannot find symbol
public class TestBasic extends TestCase{
                               ^
  symbol: class TestCase
TestBasic.java:5: error: cannot find symbol
        assertTrue(true);
        ^
  symbol:   method assertTrue(boolean)
  location: class TestBasic
3 errors

What is the reason for this?

More info:

$ echo $CLASSPATH
:/Users/sahandzarrinkoub/java/junit-X.Y.jar:/Users/sahandzarrinkoub/java/hamcrest-core-XX.YY.jar

Inside .bash_profile:

# Java
export JAVA_HOME=/Library/Java/Home
export JUNIT_HOME="$HOME/java"
export PATH="$PATH:$JUNIT_HOME"
export CLASSPATH="$CLASSPATH:$JUNIT_HOME/junit-X.Y.jar:$JUNIT_HOME/hamcrest-core-XX.YY.jar"

contents of ~/java:

$ cd ~/java
$ ls
TestBasic.java         hamcrest-core-1.3.jar  junit-4.12.jar
Sahand
  • 7,980
  • 23
  • 69
  • 137
  • 1
    what's the output of `ls /Users/sahandzarrinkoub/java/junit-X.Y.jar`? – SMA Feb 24 '18 at 14:48
  • You got me, I see the mistake – Sahand Feb 24 '18 at 14:48
  • 1
    Please, restart from scratch. You're currently learning how to install and use JUnit 3. But JUnit 4 came out in 2006, more that 12 years ago, and JUnit 5 is not in final version. So you're learning a completely obsolete framework. – JB Nizet Feb 24 '18 at 14:51
  • Should I learn JUnit 4 or 5? – Sahand Feb 24 '18 at 14:52
  • Modifying the CLASSPATH environment variable is also not something you should do. It seemed like a good idea in 1997, but we've learnt a lot since then. – JB Nizet Feb 24 '18 at 14:52
  • 1
    JUnit 4 is the current de facto standard, because JUnit 5 is still new. But going from one to the other is not a big deal. – JB Nizet Feb 24 '18 at 14:53
  • An IDE will make you life easier... – xingbin Feb 24 '18 at 14:55
  • @JBNizet, should I remove the whole excerpt from my .bash_profile then? Or just the last line? – Sahand Feb 24 '18 at 15:00
  • 1
    You should remove everything and use your IDE and your build tool to run JUnit tests. – JB Nizet Feb 24 '18 at 15:09
  • Any reason why you were/are working without an IDE? Is it an academic exercise? – Alan Blyth Feb 24 '18 at 16:51
  • Nope, it's just that it worked well for me before when mostly programming with Python. Wasn't aware of the benefits of an IDE when working with Java. – Sahand Feb 24 '18 at 21:06

0 Answers0