该类ParserTest
在包中myproject.tests
并存储在此目录结构中:
.
└── myproject
└── tests
└── ParserTest.class
为当前 shell 会话设置 CLASSPATH(没有-cp
选项,保持 java 调用干净):
export CLASSPATH=.:/usr/local/lib/java/junit-4.12.jar:/usr/local/lib/java/hamcrest-core-1.3.jar
调用 JUnit 运行器并将测试类作为参数传递:
java org.junit.runner.JUnitCore myproject/tests/ParserTest
抛出此错误:
...
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [myproject/tests/ParserTest]
...