zoukankan      html  css  js  c++  java
  • 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("测试用例");
    	}
    
    }
    
  • 相关阅读:
    PyQT_Group
    单例模式演示-1-39-07
    RSqlBuilder
    RExcel
    RJson
    NodeJs开发目录
    NodeJs事件驱动
    NodeJs实用工具util
    NodeJs之global,process
    NodeJs两个简单调试技巧
  • 原文地址:https://www.cnblogs.com/gmhappy/p/13457040.html
Copyright © 2011-2022 走看看