JUnit – Basit bir örnek

http://www.ic.sunysb.edu/stu/yosong/cse219/junit.html

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() {
;
    }
}


Source: rss