Java Reference
In-Depth Information
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class JUnitTest {
static Scanner scan;
int myIntA, myIntB, myIntC;
int[] myArrayA = {0,1,2};
Object myObject;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// access resources for use in the tests
scan = new Scanner(System.in);
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
// close resources after all tests complete
scan.close();
}
@Before
public void setUp() throws Exception {
// assign some values to the variables
// before beginning each test
myIntA = 5;
myIntB = 6;
myIntC = 7;
}
@After
public void tearDown() throws Exception {
//nothing needs to be torn down
}
@Test
public void testAssertEquals() {
// (5 + 1) equals 6
assertEquals((myIntA + 1), myIntB);
}
@Test
public void testAssertArrayEquals() {
int[] myNewArray = {0,1,2};
// the elements in both arrays are 0, 1, and 2
// order matters: {0,1,2} != {0,2,1}
assertArrayEquals(myArrayA, myNewArray);
}
@Test
public void testAssertTrue() {
Search WWH ::




Custom Search