Spring-test 單元測試使用示例
pom:
<spring.version>4.1.8.RELEASE</spring.version>
<slf4j.version>1.7.10</slf4j.version>
<log4j2.version>2.3</log4j2.version>
<disruptor.version>3.3.4</disruptor.version>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<!-- log4j2-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
</dependency>
<!-- log4j2-->
/**
* 測試基類
*/
@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<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();
}
相關文章
- Angular8單元測試示例指南Angular
- Android單元測試-作用以及簡單示例Android
- 單元測試工具 TestNG 使用
- 測試 之Java單元測試、Android單元測試JavaAndroid
- 單元測試:單元測試中的mockMock
- 使用JUnit進行單元測試
- 使用junit單元測試SpringMvcSpringMVC
- Junit 單元測試使用總結
- 在單元測試中使用EasyMockMock
- Cmocka 單元測試配置與使用Mock
- [iOS單元測試系列]單元測試編碼規範iOS
- PHP單元測試框架PHPUnit的使用PHP框架
- 使用Jest進行React單元測試React
- 使用 Spring 進行單元測試Spring
- 使用 QUnit 進行 JavaScript 單元測試JavaScript
- Flutter 單元測試Flutter
- Go單元測試Go
- 單元測試工具
- iOS 單元測試iOS
- 前端單元測試前端
- golang 單元測試Golang
- PHP 單元測試PHP
- phpunit單元測試PHP
- JUnit單元測試
- unittest單元測試
- Junit 單元測試.
- 單元測試真
- 前端測試:Part II (單元測試)前端
- vue單元測試vue test utils使用初探Vue
- 使用 PyHamcrest 執行健壯的單元測試REST
- 使用 Spring Boot 進行單元測試Spring Boot
- Laravel 單元測試認證使用者Laravel
- 安卓單元測試 (八):Junit Rule 的使用安卓
- 使用Karma、Mocha實現vue單元測試Vue
- Android單元測試(3):JUnit 的使用Android
- 單元測試之道C#版:使用NUnitC#
- JavaScript單元測試框架JavaScript框架
- React元件單元測試React元件