spring에서 testCase를 작성해보자.

junit4 annotation 종류
  • @After
    테스트시 매번 실행 후 호출되는 메소드
  • @AfterClass
    모든 테스트 후 한번 호출되는 메소드
  • @Before
    테스트시 매번 실행 전 호출되는 메소드
  • @BeforeClass
    모든 테스트 전 한번 호출되는 메소드
  • @Ignore
    skip되는 테스트 메소드
  • @Test
    테스트 메소드

exemple (spring 연동)

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sec.ams.controller.apk.TotalApkContoller;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:springmvc-servlet.xml" })
public class ApkServiceTest {
@Autowired
TotalApkContoller totalApkContoller;

@Test
public void test() {

String totalView = totalApkContoller.getTotalView();
assertEquals("apk/total", totalView);
// fail("Not yet implemented");

}
}


ref:

http://junit.sourceforge.net/javadoc/index.html

http://www.junit.org/

Posted by 뚜벅이조
,