See JUnit.org for all the latest details.
Overview for CS400 Students
JUnit is primarily about black box testing.
It is a framework for writing unit tests.
I (Deb) provided a framework for writing tests in p1.
But, JUnit's framework is much more sophisticated.
To use this more powerful tool,
you must download "their Java classes and libraries"
and learn how to use them.
The class files are bundled in a "jar" file for convenience.
To use JUnit, you must learn the format for writing tests
that can be run by the JUnit test framework.
This is similar to the work that you did
to learn to write tests for p1.
But, now you have to follow JUnit's rules (instead of Deb's).
JUnit has many features that (Deb's Unit testing framework did not have):
- GUI display of test results.
- can set timeouts for tests that take longer than you expect to wait.
- can set points (great for our graders).
- can define setup and teardown methods that create a standard base set up. The setup method is run before each new test. The teardown method is run after each test.
- can use assertTrue, assertFalse, assertEquals, etc...
- can find documentation and tutorials online from many great sources.
Some things that are similar or same between JUnit and Debs:
- Write tests that are independent of each other (to avoid cascading errors).
- Write one test to check constructor, then assume constructor is correct for other tests.
- Must know desired outcome for each tests before you can write correct conditional testing for that result.
- Can produce output in addition to the "pass/fail" counts that JUnit reports.
- Descriptive test names help immensely.
- Detailed comments for each test can save you a lot of time trying to understand and remember what exactly is being tested in each test.
- Thinking of ways to comprehensively test a type is the hardest part.