JUnit TestCase 사용예제
package test;
import junit.framework.TestCase;
public class TestServiceEx1 extends TestCase {
public void setUp () {
System.out.println("setup..");
}
public void test1() {
System.out.println("test1..");
}
public void test2() {
System.out.println("test2..");
}
}
실행결과 :
setup..
test1..
setup..
test2..
실행결과를 살펴보면
setUp() -> test1()
setUp() -> test2()
위와같은 형식으로 실행됩니다.
스프링에서 JUnit 사용예제
package test;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class TestService extends TestCase {
private ApplicationContext ctx = null;
// 각 테스트 케이스 초기화
public void setUp() {
// context를 가져옴
ctx = new FileSystemXmlApplicationContext("/web/WEB-INF/conf/applicationContext-service.xml");
// ctx = new FileSystemXmlApplicationContext(new String[] {
// "/web/WEB-INF/conf/applicationContext-service.xml",
// "/web/WEB-INF/conf/applicationContext-ibatis.xml"});
}
// 메소드명이 test로 시작
public void testService() {
net.daum.sori.bean.Bean service = (net.daum.sori.bean.Bean)ctx.getBean("showTime");
//System.out.println(service.getTime());
// 예상값과 비교
assertEquals( "20071107", service.getTime());
}
}

이올린에 북마크하기
Prev
Rss Feed