Spring-Test 单元测试使用示例

pom:

4.1.8.RELEASE
1.7.10
2.3
3.3.4

 


            org.springframework
            spring-test
            ${spring.version}
            test
            
                
                    junit
                    junit
                
            
        

        
            org.testng
            testng
            6.7
        

        
            junit
            junit
            4.10
            test
        

        
        
            org.slf4j
            slf4j-api
            ${slf4j.version}
        
        
            org.slf4j
            jcl-over-slf4j
            ${slf4j.version}
        
        
            org.slf4j
            jul-to-slf4j
            ${slf4j.version}
        
        
            org.apache.logging.log4j
            log4j-api
            ${log4j2.version}
        
        
            org.apache.logging.log4j
            log4j-core
            ${log4j2.version}
        
        
            org.apache.logging.log4j
            log4j-slf4j-impl
            ${log4j2.version}
        
        
            org.apache.logging.log4j
            log4j-1.2-api
            ${log4j2.version}
        
        
            com.lmax
            disruptor
            ${disruptor.version}
        

        

 

 

基类:

 

/**
 * 测试基类
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
        locations = {"classpath*:config/spring/common/appcontext-*.xml",
                "classpath*:config/spring/local/appcontext-*.xml",
                "classpath*:config/spring/local/emidas-coupon-*.xml"})
public abstract class AbstractTest {

}

 

 

测试类:

public class Test extends AbstractTest{

    private static final Logger logger = LogUtil.get(Test.class);

    @Autowired
    private PrizePackageService prizePackageService;
    @Autowired
    private PrizeShopMapper prizeShopMapper;
    @Autowired
    private PrizePoolMapper prizePoolMapper;
    @Autowired
    private PrizePackageMapper prizePackageMapper;
    @Autowired
    private PrizeRemoteService prizeRemoteService;
    @Autowired
    private CacheClient cacheClient;

    @Autowired
    private BonusEventService bonusEventService;
    @Autowired
    private MqService mqService;
    @Autowired
    private PrizeMapper prizeMapper;

    @Autowired
    private Main main;
    @Autowired
    @Qualifier("oldJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private LotteryRemoteService lotteryRemoteService;
    private AtomicReference sign =new AtomicReference();

    @Autowired
    private HelpUtil helpUtil;
    @Autowired
    private ShopService shopService;

    @org.junit.Test
    public void randomDraw(){
        PrizePackageDTO prizePackageDTO = prizeRemoteService.loadPrizePackage(16302);
        prizePackageDTO.setDrawMethod(DrawMethodEnum.RANDOM);
        Response response = prizeRemoteService.updatePrizePackage(prizePackageDTO);
        System.out.println(response);

        //17963 17974 17976
        RandomConfigDTO randomConfigDTO = new RandomConfigDTO();
        randomConfigDTO.setPackageId(16302);
        randomConfigDTO.setPrizeLevel(PrizeLevelEnum.BIG_PRIZE);
        List randoms = new ArrayList();

        PrizeRandomDTO randomDTO = new PrizeRandomDTO();
        randomDTO.setPrizeId(17963);
        randomDTO.setPercent(new BigDecimal("10"));
        randoms.add(randomDTO);

        randomDTO = new PrizeRandomDTO();
        randomDTO.setPrizeId(17974);
        randomDTO.setPercent(new BigDecimal("20"));
        randoms.add(randomDTO);

        randomDTO = new PrizeRandomDTO();
        randomDTO.setPrizeId(17976);
        randomDTO.setPercent(new BigDecimal("30"));
        randoms.add(randomDTO);

        randomDTO = new PrizeRandomDTO();
        randomDTO.setPrizeId(0);
        randomDTO.setPercent(new BigDecimal("40"));
        randoms.add(randomDTO);

        randomConfigDTO.setPrizeRandomDTOs(randoms);

        Response randomResponse = prizeRemoteService.configPrizeRandom(randomConfigDTO);
        System.out.println(randomConfigDTO);

        System.out.println();

    }

 

 

 

 

 

 

 

你可能感兴趣的:(Spring-单元测试)