SpringBoot 編寫測試用例出現異常: java.lang.Exception: No tests found matching的原因


SpringBoo編寫測試用例出現異常:java.lang.Exception: No tests found matching異常可能的原因:

  • 沒加 @Test注解;
  • 可能是spring-test版本和Junit4不兼容;
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-test</artifactId>
    	<scope>test</scope>
    </dependency>
    
  • 測試用例不能用 static靜態修飾;
  • 測試用例需無參無返回值;
  • 測試類所在的包名,此src/test/java下的包名需要與src/main/java里邊定義的包名一致;
  • 方法前需加public關鍵字;

    ps:我使用的junit4 (eclipse自帶的)測試方法必須要加上public作用域(之前沒有加)

完整版:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
	@Test
	public void contextLoads() {
		System.out.println("測試用例");
	}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM