Can You Write a JUnit 4.4 Test Class Template in 2 Minutes?
JUnit Questions and Answers
(Continued from previous question...)
Can You Write a JUnit 4.4 Test Class Template in 2 Minutes?
Writing JUnit 4.4 test class template is not that hard. You should be able to do it within 2 minutes.
Here is a nice sample template:
import org.junit.*;
import static org.junit.Assert.*;
public class JUnit44Test {
private java.util.List emptyList;
/**
* Sets up the test fixture.
* (Called before every test case method.)
*/
@Before
public void setUp() {
emptyList = new java.util.ArrayList();
}
/**
* Tears down the test fixture.
* (Called after every test case method.)
*/
@After
public void tearDown() {
emptyList = null;
}
@Test
public void testSomeBehavior() {
assertEquals("Empty list should have 0 elements",
0, emptyList.size());
}
@Test(expected=IndexOutOfBoundsException.class)
public void testForException() {
Object o = emptyList.get(0);
}
}
(Continued on next question...)
Other Interview Questions
|