테스트케이스 작성 및 수행 실습
프로젝트 import
[File] - [Import] 선택 후 아래 창에서 Existing Project into Workspace 클릭
아래 압축파일 선택 후 [Finish]
임포트된 프로젝트를 확인하면 아래와 같이 테스트 소스가 있다
아래 코드를 입력하고 프로젝트 우클릭 - Run As - JUnit Test 클릭하면 테스트가 실행된다.
import static org.junit.Assert.assertEquals;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/context-helloworld.xml" })
public class HelloWorldServiceTest {
private HelloWorldService helloworld;
@Resource(name = "helloworld")
public void setHelloworld(HelloWorldService hello) { // HelloWorldService를 bean 설정에 의해 주입받는다
this.helloworld = hello;
}
@Test
public void SayHello() {
assertEquals("Hello eGovFrame!!!", helloworld.sayHello());
}
}
아래화 같이 결과를 화면으로 볼 수 있다.
유용한 단축키
ctrl + shift + o : 필요한 패키지를 한번에 import