Skip to content

JUnit

JUnit is a lightweight framework for automating unit testing in Java.

unit testing

Verify that a particular piece of code works properly in isolation.

To test a piece of code, we write a test class, or test case, in Java.

  • Purpose: run methods of our code.
  • Strategy: use outputs of our code's methods and check if those outputs are the values we expect.

JUnit is included in Eclipse, so we can run our test class and see if our methods worked.

Class + Test Class + JUnit

Drill

UnitTesting/test/com.example.unittesting.drills.StringManipulatorTests * In Package Explorer, right-click the StringManipulatorTests class and choose Run As->JUnit Test. (Note that the package is in the test source directory.)

Run As

  • See what happens.

Prev -- Up -- Next