up previous next contents
Next: A sample JUnit session Up: JUnit Previous: Goals of unit testing?   Contents

Subsections

Unit Testing with JUnit


How to create unit tests with JUnit

  1. Build a subclass of the class TestCase.
  2. Create as many test methods in this test class as necessary. 
  3. With JUnit, if each method begins with the name "test", like testThis(), testThat(), etc., the test methods will be discovered automatically.
  4. The testing framework collects up all the tests and executes them one after another.
  5. You can create a method named setUp() that sets stuff up before each test is run.
  6. You can create a method named tearDown() that helps you get rid of stuff after each test is run.


Next: A sample JUnit session Up: JUnit Previous: Goals of unit testing?   Contents