2009. 3. 11. 22:04

JUnit Test

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.*;

public class InvalidValueTest {
private int x;
@BeforeClass
public static void initOnce(){
System.out.println("init Once");
}
@AfterClass
public static void releaseOnce(){
System.out.println("release Once");
}
@Before
public void init(){
x = 20;
}
@After
public void release(){
x = 0;
}
@Test
public void countOne(){
for(int i = 0; i < 100; i++){
x++;
}
System.out.println("countOne's x=" + x);
}
@Test
public void countTwo(){
for(int i = 0; i < 10; i++){
x++;
}
System.out.println("countTwo's x=" + x);
}
@Test
public void booleanTrue(){
assertTrue(1==1);
}
@Test
public void booleanFalse(){
assertFalse(1!=1);
}
@Test(expected=ArithmeticException.class)
public void divisionByZero(){
int number = 3/0;
try{
int number1 = 3/0;
}
catch(ArithmeticException e){
e.printStackTrace();
}
}
@Ignore("not ready yet")
@Test
public void getPriceOfNewItem(){
System.out.println("Ignore Test Method()");
}
@Test(timeout=10000)
public void timeout_method(){
for(double i = 0; i < 999999999; i++){
}
}

}

Trackback 0 Comment 0