![]() |
![]() |
|
Many IDEs have JUnit built-in (e.g. eclipse and BlueJ). However, if you get a compile-time error about “class junit.framework.TestCase not found”, it means that the following two steps haven't both been done: (a) you have JUnit .jar(s) downloaded somewhere on your computer, and (b) your CLASSPATH includes it. You can do these two thing from inside your IDE, or from the command-line (which this page is all about).
optional: It is not a requirement to use JUnit for our ITEC380 project. You can strip out the mentions of the JUnit classes, and write your own:
void assertEquals( Object actual, Object expected ) { if (!actual.equals(expected)) { System.err.printf("assertion failed:\nExpect: %s\nActual: %s\n", expected.toString(), actual.toString() ); } }
One student reports: After downloading the two JUnit .jar files (below), I added them to the reference library for the project that I added the OG0 .jar file to originally. Then I could right click and select Run As and select JUnit Test. I could run individual test methods/classes, or specify running all tests within the entire .jar file.
If somebody sends me (links to) good instructions for running/installing JUnit from inside other IDEs, send me a link and I'll put it here.
JUnit test-classes don't have a main. So instead, we can trigger the tests by running org.junit.runner.JUnitCore's main, passing it the name(s) of what test-classes to run:
java org.junit.runner.JUnitCore MyTestClass |
public static void main(String... args) { ExprTest t = new ExprTest(); t.setUp(); t.testMethod1(); t.tearDown(); t.setUp(); t.testMethod2(); t.tearDown(); } |
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |