본문 바로가기
FullStack/21. Java

SpringWeb 소스 JUNIT 을 이용한 테스트

by nakanara 2013. 3. 14.
반응형

package com.nakanara;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.nakanara.service.UserService;
import com.nakanara.service.UserVO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
          "classpath:egovframework/spring/com/context-datasource.xml",
          "classpath:egovframework/spring/com/context-aspect.xml",
          "classpath:egovframework/spring/com/context-common.xml",
          "classpath:egovframework/spring/com/context-excel.xml",
          "classpath:egovframework/spring/com/context-idgen.xml",
          "classpath:egovframework/spring/com/context-mail.xml",
          "classpath:egovframework/spring/com/context-properties.xml",
//          "classpath:egovframework/spring/com/context-security.xml",
          "classpath:egovframework/spring/com/context-sqlMap.xml",
          "classpath:egovframework/spring/com/context-transaction.xml",
          "classpath:egovframework/spring/com/context-validator.xml"
         
          })
@Transactional
@TransactionConfiguration(transactionManager="txManager" , defaultRollback=true)
public class UserTest {
    
     @Resource(name="userService")
     private UserService userService;
    
     Log logger = LogFactory.getLog(this.getClass());
    
     @Test
     public void 사용자입력테스트() throws Exception{
         
          int count = userService.selectUserCnt("TEST_001");
         
          logger.info("Count=" + count);
         
         
          UserVO userVO = new UserVO();
                  
          userVO.Name(“TEST_001”);
         userService.saveUser(userVO);
         
          count = userService. selectUserCnt ("TEST_001");         
                   
          logger.info("Count=" + count);
          logger.info("입력="+ userService);
          assertEquals("입력 여부=" , count, 1);
         
     }

}

반응형