Fundamental classes in JUnit include the test class, test suite, and test runner.
A
test class must be a public class and have a zero-argument constructor. A test class may have one or more test methods which must be public, return void, take no arguments and have the @Test annotation. New instances of JUnit test classes are instantiated for each test method, so instance variables are not reusable.
Test classes use
assert methods to determine whether or not expected values match the actual value. An example of an assert method would be assertSame. AssertSame takes three arguments (the first argument is the error message to present, then the expected value, and finally the actual value). Assert methods will throw AssertionError with a specified message if the assertion fails.
A
test runner provides a way to specify how to run a test. The JUnitCore facade (which interfaces with test runners) provides a way to run tests and gather results.
A
test suite is a collection of tests and/or other test suites. A class is defined with the RunWith and SuiteClasses annotations. A runner is specified with @RunWith(value=Runner
.class) and the tests/suites are specified with @SuiteClasses(value={Test. class, Suite.class, ... } ).
Integration of suites with IDEs, Ant, and Maven is possible and recommended.