spring service junit test

■ 샘플소스

import static org.junit.Assert.assertNotNull ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.fail ;

import java.util.List;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
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 org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
        "classpath:/junit_test/datasource-config.xml" ,
        "classpath:/junit_test/root-context.xml"
})
@WebAppConfiguration
public class SchedulerServiceTest {

        private Logger logger = Logger.getLogger (this .getClass());
       
        private Object obj   = null;
       
        @Autowired
        private SampleService sampleService;
       
        @Before
        public void setUp() {
               logger.debug( "각 테스트가 시작되기 전에 실행된다." );
       }
       
        @After
        public void shutDown() {
               logger.debug( "각 테스트가 끝난 후에 실행된다." );
       }
       
        @Test
        public void testList_리스트_조회() {
              List<Object> list = sampleService.list();
               logger.debug( "[mirinae.maru] list size : " + list .size() );
               assertNotNull( list );
       }

        @Ignore
        public void testUpdateData() {
               fail("Not yet implemented");
       }

        @Test
        @Transactional
        public void testDeleteData_데이터_삭제_테스트() {
              
              Object obj = new Object();
               int result = sampleService.deleteData(obj);
              
               assertTrue( result>0 );
       }
}

 

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다