appendix-a
Appendix A. Brief JUnit 4 tutorial
![]() |
We get assertion methods from JUnit’s Assert class through a static import. |
![]() |
The name of the class should indicate that it’s a test—for example, have the class name start with Test. |
![]() |
The instance variables set up in the @Before method represent the common fixture for the test methods. |
![]() |
We can prepare a known state for the test by tagging a public method with the @Before annotation. |
![]() |
We can clean up after our test by tagging a public method with the @After annotation. |
![]() |
All public void methods tagged with @Test are considered test cases by the JUnit 4 TestRunner. |
![]() |
Test methods can declare any exceptions—JUnit catches them. |
![]() |
The @Test annotation also allows for timing tests, testing for expected exceptions, and so on. |
![]() |
We can declare any number of helper methods as long as they don’t look like test methods. |








