3

I've looked at the duplicate questions here and elsewhere, including the JUnit FAQ (http://junit.sourceforge.net/doc/faq/faq.htm#running_1).

junit-4.10.jar is at /Library/Java/Extensions which is automatically on the classpath.

My test class is compiled in my working directory. It is not part of any package. However, none of these work:

java org.junit.runner.JUnitCore TestBoard
java -cp . org.junit.runner.JUnitCore TestBoard

Both return:

JUnit version 4.10
Could not find class: TestBoard

Time: 0.001

OK (0 tests)
Dan
  • 763
  • 3
  • 8
  • 13
  • 1
    Is TestBoard the complete name of your class (ie, TestBoard is not part of a package)? – Apprentice Queue Sep 17 '12 at 04:06
  • 1
    where is TestBoard.class present and where are running this `java` command from (directories)? – Vikdor Sep 17 '12 at 04:07
  • @ApprenticeQueue TestBoard is the complete name of the class, not part of a package. – Dan Sep 18 '12 at 16:02
  • @Vikdor TestBoard.class is in the same directory from which I am running the `java` commands. – Dan Sep 18 '12 at 16:02
  • I suggest you associate a package to TestBoard (eg, `package test`) and then try running with `test.TestBoard`. – Apprentice Queue Sep 19 '12 at 15:35
  • 1
    I'm having the exact same problem. This question has been posted on StackOverflow so many times and none of the answers have helped. This one isn't even answered! – wkschwartz Jul 16 '13 at 02:36
  • Same same SAME as @wkschwartz :( – Joe Sak Feb 15 '14 at 19:10
  • @wkschwartz it would help if you provide source code for your test. Provide the simplest possible test that you think should work but isn't working. My guess is that `TestBoard.class` isn't in your classpath. – NamshubWriter Feb 24 '14 at 16:20
  • Unfortunately, since I couldn't get JUnit tests working for so long, I gave up and just wrote some Python code to test input/output from the whole program. – wkschwartz Feb 24 '14 at 18:27

2 Answers2

0

The best way to determine if this is a problem with JUnit or a problem with your class and/or classpath would be to add a main method to your test class:

public class TestBoard extends TestCase {

  public void testThatShouldFail() {
    fail();
  }

  public static void main(String[] args) {
    System.err.println("Hello World!");
  }
}

Then you can run:

javac TestBoard.java
java TestBoard

If this does not print "Hello World!" then it's some problem with your environment (classpath issue, etc) or your test class.

My best guess is you forgot to make the class public.

NamshubWriter
  • 23,549
  • 2
  • 41
  • 59
0

Recent I had similar problem with my junits tests. Running tests ('mvn test' in my case) caused few types of misleading execptions. As it turned out i was using jdk 1.6 in my project. When i've switched to jdk 1.7 everything ended.

Hejwo
  • 380
  • 5
  • 13