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