Created
July 10, 2012 17:06
-
-
Save rballen/3084744 to your computer and use it in GitHub Desktop.
java: junit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // setUp and teaerDown | |
| @Before | |
| public void setUp() { | |
| System.out.println("@Before goes before every JUnit4 test - setUp "); | |
| } | |
| @After | |
| public void tearDown() { | |
| System.out.println("@After goes before every JUnit4 tearDown"); | |
| } | |
| //once per class - initializers | |
| @BeforeClass | |
| public static void setUpClass() throws Exception { | |
| System.out.println("@BeforeClass method will be executed before JUnit test for" | |
| + "a Class starts"); | |
| } | |
| @AfterClass | |
| public static void tearDownClass() throws Exception { | |
| System.out.println("@AfterClass method will be executed after JUnit test for" | |
| + "a Class Completed"); | |
| } | |
| // duh | |
| @Test | |
| public void testCalculateInterest() { | |
| System.out.println("calculateInterest"); | |
| fail("An Example of @Test JUnit4 annotation"); | |
| } | |
| @Ignore("Not yet implemented") | |
| @Test | |
| public void testGetAmount() { | |
| System.out.println("getAmount"); | |
| fail("@Ignore method will not run by JUnit4"); | |
| } | |
| @Test(timeout = 500) | |
| public void testTimeout() { | |
| System.out.println("@Test(timeout) can be used to enforce timeout in JUnit4 test case"); | |
| while (1 == 1) { | |
| } | |
| } | |
| @Test(expected=IllegalArgumentException.class) | |
| public void testException(int input) { | |
| System.out.println("@Test(expected) will check for specified exception during its run"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment