这一定很明显,但是在查看此处和其他地方后我仍然卡住。我想从命令行运行我的Junit测试。我做了一个脚本化的部署过程,我想在部署之前进行验证。从命令行运行Junit(Mac)
我可以运行此: java命令:/路径/的junit-4.8.1.jar org.junit.runner.JUnitCore HappyPath.class
,我此目录中。类文件。
$ ls -lart
total 40
-rw-r--r-- 1 rdejournett staff 144 Sep 22 12:09 package-info.class
-rw-r--r-- 1 rdejournett staff 11001 Sep 22 12:09 HappyPath.class
drwxr-xr-x 5 rdejournett staff 170 Sep 22 12:09 ..
-rw-r--r-- 1 rdejournett staff 660 Sep 22 12:13 AllTests.class
drwxr-xr-x 5 rdejournett staff 170 Sep 22 12:13 .
但输出是:
JUnit version 4.8.1
Could not find class: HappyPath.class
Time: 0
OK (0 tests)
我需要创建一个JAR文件?
HappyPath类看起来像这样。
@Test
public static void happyPath() {
String xml = "";
xml = ReadJson.ReadFile("/app/mirth/UnitTests/GEoutput.xml");
Statements s = new Statements();
// need XmlDocRoot tag or whatever to parse it properly
try {
s = ConvertXmltoObj(xml);
happyPathStatement(s);
happyPathGuarantor(s);
happyPathAging(s);
happyPathEncounters(s);
happyPathEncounterCharges(s);
} catch (JAXBException e) {
e.printStackTrace();
fail();
} catch (ParserConfigurationException e) {
e.printStackTrace();
fail();
} catch (SAXException e) {
e.printStackTrace();
fail();
} catch (IOException e) {
e.printStackTrace();
fail();
}
assertTrue(true);
}
更新:
删除了的.class,所以命令是这样的:
java -cp .:/path/junit-4.8.1.jar org.junit.runner.JUnitCore HappyPath
获得现在这个错误:
JUnit version 4.8.1
Exception in thread "main" java.lang.NoClassDefFoundError: HappyPath (wrong name: com/xxx/xxx/datamodel/ge/HappyPath)
at java.lang.ClassLoader.defineClass1(Native Method)
2015-09-22
Rob
+1
抛弃'.class'。 –
+1
使用类似maven或gradle的东西来构建您的项目。它带有junit支持,因此您可以轻松运行测试。 –
+0
谢谢,现在得到它:JUnit版本4.8.1 线程“main”中的异常java.lang.NoClassDefFoundError:HappyPath(错误名称:com/xxx/xxx/datamodel/ge/HappyPath) \t at java.lang.ClassLoader .defineClass1(本地方法) –