Compsci 100, Using JUnit

Using JUnit

To test your code you're often be given testing code and you may sometimes develop your own tests. When dode tests individual methods in your class, these tests are called unit tests and so you need to use the standard JUnit unit-testing library with the appropriate Java class files to test your classes.

To choose Run as JUnit test first use the Run As option in the Run menu as shonw on the left below. You have to select the JUnit option as shown on the right below. Most of you will have that as the only option, I have two "run as" options on my machine.

run as   run as choose

You may often be given several testing methods in the JUnit test code provided as part of an assignment. Each testing method is preceeded by the annotation @Test as you can see in testing code provided as part of both the DNA assignment and the Boggle assignment

If the JUnit tests pass, you'll get all green as shown on the left below. That screenshot was taken using the testing class provided as part the DNA assignment with its SimpleStrand class

Otherwise you'll get red -- on the right below -- and an indication of the first test to fail. Fix that, go on to more tests. The red was obtained from a an implemrentation of the DNA assignment LinkStrand that had nothing but code-stubs generated by Eclipse (with a constructor added).

green junit   red junit