Monday, December 17, 2012

JUnit


A JUnit test fixture is a Java object. With older versions of JUnit, fixtures had to inherit from junit.framework.TestCase, but new tests using JUnit 4 should not do this.[2] Test methods must be annotated by the @Test annotation. If the situation requires it,[3] it is also possible to define a method to execute before (or after) each (or all) of the test methods with the @Before (or@After) and @BeforeClass (or @AfterClass) annotations.[4]


import org.junit.*;
 
public class TestFoobar{
    @BeforeClass
    public static void setUpClass() throws Exception {
        // Code executed before the first test method       
    }
 
    @Before
    public void setUp() throws Exception {
        // Code executed before each test    
    }
 
    @Test
    public void testOneThing() {
        // Code that tests one thing
    }
 
    @Test
    public void testAnotherThing() {
        // Code that tests another thing
    }
 
    @Test
    public void testSomethingElse() {
        // Code that tests something else
    }
    @After
    public void tearDown() throws Exception {
        // Code executed after each test   
    }
 
    @AfterClass
    public static void tearDownClass() throws Exception {
        // Code executed after the last test method 
    }
}



http://www.vogella.com/articles/JUnit/article.html

No comments:

Post a Comment