This must be obvious, but I'm stuck after looking here and elsewhere. I want to run my Junit test from the command line. I do a scripted deployment process and I want to verify before doing the deployment.
I found this SO but I'm getting an error (more below). How to run JUnit test cases from the command line
I can run this: java -cp .:/path/junit-4.8.1.jar org.junit.runner.JUnitCore HappyPath.class
and I am in this directory with the .class file.
$ 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 .
But the output is:
JUnit version 4.8.1
Could not find class: HappyPath.class
Time: 0
OK (0 tests)
Do I need to create a JAR file?
The HappyPath class looks like this.
@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);
}
Update:
Removed the .class, so command is this:
java -cp .:/path/junit-4.8.1.jar org.junit.runner.JUnitCore HappyPath
Getting this error now:
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)