1. 程式人生 > >springboot裡的junit測試

springboot裡的junit測試

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-test</artifactId>
      <version>2.0.3.RELEASE</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>4.3.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version> 4.12</version>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>1.3</version>
      <scope>test</scope>
    </dependency>

新增以上依賴。或使用springboot的starter包:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <version> 1.5.1.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>4.3.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version> 4.12</version>
    </dependency>
@RunWith(SpringRunner.class)  
@SpringBootTest(classes=SingleApplicationMain.class)
public class ApplicationTest {

	@Autowired
	AccountRecRepository wcAccountRecRepository;
    
  @Test  
  public void test() throws InterruptedException {  
		
  	AccountRecQueryParam param = new AccountRecQueryParam();
  	param.setMemId("8e2eb107-8236-471b-a58b-199cfa309f08");
  	Pageable pageable = new PageRequest(0,10, Sort.Direction.DESC,"created_time");
		Page<AccountRecEntity> page = this.wcAccountRecRepository.findAccountRecPageNative((param), pageable);
		param.setMemId("");
  }

}