Skip to content

Instantly share code, notes, and snippets.

@miguelpardal
Created March 28, 2015 11:37
Show Gist options
  • Save miguelpardal/1164220fabfb647b47a2 to your computer and use it in GitHub Desktop.
Save miguelpardal/1164220fabfb647b47a2 to your computer and use it in GitHub Desktop.
JUnit 4 example test class
package example.test;
import org.junit.*;
import static org.junit.Assert.*;
/**
* Test suite
*/
public class ExampleTest {
// static members
// one-time initialization and clean-up
@BeforeClass
public static void oneTimeSetUp() {
}
@AfterClass
public static void oneTimeTearDown() {
}
// members
// initialization and clean-up for each test
@Before
public void setUp() {
}
@After
public void tearDown() {
}
// tests
@Test
public void test() {
// assertEquals(expected, actual);
// if the assert fails, the test fails
}
@Test(expected=ExampleException.class)
public void testException() throws Exception {
// JUnit expects the exception declared in the annotation
// if it is not thrown, the test fails
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment