SE450: JUnit: Running from the Command Line [36/41] ![]() ![]() ![]() |
To run the command line version of JUnit (the one run from inside ant)
java junit.textui.TestRunnerAnd you will get the following usage statement:
Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class
Just supply the full name of the test you want to run to the application, and it will run the test. You will see a . for each test run, and an F for each failed test.
The -wait
parameter is useful for those of you who
might run a test in a command window in Windows 9X from a batch file, and
the window disappears. The test will stop and wait for a carriage return.
Sample output:
... Time: 0.01 OK (3 tests)
In this case, there were 3 tests and all passed. If there were failures, we would see something like this:
...F Time: 0.01 There was 1 failure: 1) testHardGrade(se450.student.hw3.MainTest)junit.framework.AssertionFailedError: Hard Grade expected:<D> but was:<A> at se450.student.hw3.MainTest.testHardGrade(MainTest.java:97) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) FAILURES!!! Tests run: 3, Failures: 1, Errors: 0
As you see it is a bit more dramatic.
The junit.jar file, your compiled test code, and your
compiled code that is being tested must all be in your
classpath for the TestRunner to succeed. In your se450
development directory, your CLASSPATH
would
need to be set to build;lib\junit.jar
to run
correctly.