1

The class ParserTest is in the package myproject.tests and stored in this directory structure:

.
└── myproject
    └── tests
        └── ParserTest.class

Set the CLASSPATH for the current shell session (no -cp option, to keep to java call clean):

export CLASSPATH=.:/usr/local/lib/java/junit-4.12.jar:/usr/local/lib/java/hamcrest-core-1.3.jar

Call the JUnit runner and pass the test class as the argument:

java org.junit.runner.JUnitCore myproject/tests/ParserTest

This error gets thrown:

...
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [myproject/tests/ParserTest]
...
Senkaku
  • 197
  • 2
  • 10
  • 1
    It took me some time to figure that out and because I have not found anything on StackExchange (with my searchterms), I wrote this Q/A to help people that face the same problem and use the same lingo to search for a solution. – Senkaku Oct 22 '15 at 18:37

1 Answers1

0

org.junit.runner.JUnitCore requires the argument to use . as a separator between directories and classes, instead of /.

The calltrace looks like that and ends in java.lang.Class.forName(classname):

JUnitCore.main(args)
└── JUnitCore.runMain(args)
    └── JUnitCommandLineParseResult.parse(args)
        └── new JUnitCommandLineParseResult().parseArgs(args);
            └── JUnitCommandLineParseResult.parseParameters(...);
                └── ...
                    └── org.junit.internal.Classes.getClass(arg);
                        └── java.lang.Class.forName(className);

The JavaDoc for java.lang.Class.forName(String className) says:

Parameters: className - the fully qualified name of the desired class.

And in Java, fully qualified names are written with . not /.

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
Senkaku
  • 197
  • 2
  • 10