Video Tutorial 5 - JUnit Download the video tutorial (high resolution, may need additional codecs) or view the video tutorial by clicking on the "play" button below.
The following code can be used as a template for creating a JUnit test class:
import org.junit.*;
public class ExampleTest {
/**
* methods annotated with @BeforeClass are
* called once before the test methods run
*/
@BeforeClass
public static void setUpBeforeClass() {
;
}
/**
* methods annotated with @AfterClass are
* called once after all test methods run
*/
@AfterClass
public static void tearDownAfterClass() {
;
}
/**
* methods annotated with @Before are
* called before every test case method
*/
@Before
public void setUp() {
;
}
/**
* methods annotated with @After are
* called after every test case method
*/
@After
public void tearDown() {
;
}
/**
* methods annotated with @Test are
* your actual Unit Test methods
* test using:
* Assert.assertEquals
* Assert.assertTrue
* Assert.assertFalse
* Assert.assertNotNull
* Assert.assertNull
* etc.
*/
@Test
public void firstTest() {
;
}
@Test
public void secondTest() {
;
}
@Test(expected=Exception.class)
public void checkExceptionTest() {
;
}
}