dimanche 16 décembre 2018

How to run Junit tests from command line on windows with no package?

I have a folder(which is where I am running all commands) called learning. Inside this folder, I have two files, one is called Driver.java which is a simple main class with a simple hello world method. The other file is DriverTest.java which has this code as shown below.

import static org.junit.Assert.*;
import org.junit.Test;

public class DriverTest {
    @Test
    public void test() {
        fail("Not yet implemented");
    }
}

Apart from this I have JUnit 4.13-beta jar inside the same learning folder.

Now I open command line in windows and go to learning folder location and run this command.

javac -cp junit-4.13-beta-1.jar;. *.java

It didn't give me any errors, hence it has compiled both Driver and DriverTest java files.

Now I am trying to run the JUnit test using this command.

java -cp junit-4.13-beta-1.jar org.junit.runner.JUnitCore DriverTest

But I am getting this error:

JUnit version 4.13-beta-1
.E
Time: 0.002
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [DriverTest]
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
        at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
        at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
        at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
        at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: DriverTest
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.junit.internal.Classes.getClass(Classes.java:42)
        at org.junit.internal.Classes.getClass(Classes.java:27)
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:98)
        ... 4 more

FAILURES!!!
Tests run: 1,  Failures: 1

Why is my DriverTest class not found? Its right there in the same folder right?

Aucun commentaire:

Enregistrer un commentaire