지금까지 작성된 내용으로 ApplicationContext의 Bean을 호출해서 테스트해볼까,
하는김에 Junit 테스트도 해보고,,,
* Junit 3.x version
* $Id: MailControllerTest.java ,v 1.1 2010. 9. 9. 오전 11:53:33 dongbuFarm Exp $
* created by : An Sang Kil
* creation-date : 2010. 9. 9.
* =========================================================
* Copyright (c) 2010 ManInSoft, Inc. All rights reserved.
*/
package com.hynix.ecms.mail;
import org.apache.log4j.Logger;
import org.apache.struts.mock.MockHttpServletRequest;
import org.apache.struts.mock.MockHttpServletResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hynix.ecms.common.mail.controller.MailController;
public class MailController_Test extends AbstractDependencyInjectionSpringContextTests {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(MailController_Test.class);
public static void main(String args[]){
ApplicationContext ctx = new FileSystemXmlApplicationContext(
new String[] { "/WebContent/WEB-INF/contextLoaderMail-servlet.xml",
"/WebContent/WEB-INF/applicationContext/applicationContext-mail.xml"
});
MailController mailController = (MailController) ctx.getBean("mailController");
try {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setAttribute("key", "common");
mailController.goMailWritePage(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
* Junit 4.x version 테스트
* $Id: MailControllerTest.java ,v 1.1 2010. 9. 9. 오전 11:53:33 dongbuFarm Exp $
* created by : An Sang Kil
* creation-date : 2010. 9. 9.
* =========================================================
* Copyright (c) 2010 ManInSoft, Inc. All rights reserved.
*/
package com.hynix.ecms.mail;
import org.apache.log4j.Logger;
import org.apache.struts.mock.MockHttpServletRequest;
import org.apache.struts.mock.MockHttpServletResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hynix.ecms.common.mail.controller.MailController;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"file:WebContent/WEB-INF/contextLoaderMail-servlet.xml",
"file:WebContent/WEB-INF/applicationContext/applicationContext-mail.xml"
})
public class MailController_Test extends AbstractDependencyInjectionSpringContextTests {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(MailController_Test.class);
@Autowired
private MailController mailController;
@Test
public void testMailController(){
try {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setAttribute("key", "common");
mailController.goMailWritePage(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
결과는 똑같음, @After와 @Befor은 다음에 필요하다면 사용하지뭐,
참고로 J test하다가 org.springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass
혹은 이거랑 비슷한 notFountClasss..... 같은 버전의 이클립스랑 같은 라이브러리를 사용하는데 어느 프로젝트에서는 이런에러가난다. .Setting 폴더에서 수정하라고 하는데, 이건 완전 헐이고,
중요한건, 저에러는 내가 Spring ver 하고 Junit ver이 안맞아서 저런단다. 가장 빨리 하고 싶으면 깔끔하게 프로젝트 세로 만드세요 ㅎㅎ 더좋은 방법이 있다면 댓글로 저도 알려주시길..
'Spring' 카테고리의 다른 글
Spring Timer Sample (0) | 2010.12.14 |
---|---|
Ibitis ResultMap XML 자동 생성하기. (0) | 2010.09.14 |
Junit Spring ApplicationContext (Applacation Bean Test, Spring Bean Call) (0) | 2010.09.08 |
SpringFramework *.property 사용방법 (0) | 2010.05.06 |
Spring applicatioContext-*** (0) | 2009.01.08 |