Spring-单元测试

1.加入单元测试的包

2.单元测试基类:

/**
 * 测试基类
 */
@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 {
 
}

3.写具体的测试类

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<Thread> sign =new AtomicReference<Thread>();
 
    @Autowired
    private HelpUtil helpUtil;
    @Autowired
    private ShopService shopService;
 
    @org.junit.Test
    public void randomDraw(){
        PrizePackageDTO prizePackageDTO = prizeRemoteService.loadPrizePackage(16302);
        prizePackageDTO.setDrawMethod(DrawMethodEnum.RANDOM);
        Response<PrizePackageDTO> response = prizeRemoteService.updatePrizePackage(prizePackageDTO);
        System.out.println(response);
 
        //17963 17974 17976
        RandomConfigDTO randomConfigDTO = new RandomConfigDTO();
        randomConfigDTO.setPackageId(16302);
        randomConfigDTO.setPrizeLevel(PrizeLevelEnum.BIG_PRIZE);
        List<PrizeRandomDTO> randoms = new ArrayList<PrizeRandomDTO>();
 
        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<Boolean> randomResponse = prizeRemoteService.configPrizeRandom(randomConfigDTO);
        System.out.println(randomConfigDTO);
 
        System.out.println();
 
    }

原文地址:https://blog.csdn.net/z69183787/article/details/73201562

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值