单元测试 报错:ava.lang.Exception: No tests found matching

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=getHello], {ExactMatcher:fDisplayName=getHello(com.example.demo.DemoApplicationTests)], {LeadingIdentifierMatcher:fClassName=com.example.demo.DemoApplicationTests,fLeadingIdentifier=getHello]] from org.junit.internal.requests.ClassRequest@19a81e8
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)


错误提示如上
错误代码如下:

import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment =SpringBootTest.WebEnvironment.RANDOM_PORT)
class DemoApplicationTests {
     
    @LocalServerPort
    private int port;
    
    private URL base;
    
    @Autowired
    private TestRestTemplate testr;
    
    @Before
    public void setUp() throws Exception  {
        
            this.base =new URL("http://localhost:" +port +"/hello");
        
    
    
    @Test
    public void getHello() {
        ResponseEntity<String>rEntity 
        =testr.getForEntity(base.toString(), String.class); 
        
        System.out.println(rEntity.getBody());
    }
    

    @Test
    public void contextLoads() {
    }

}

解决办法:类上面一定得加public修饰!因为我这个项目是 在网上导入的模板,测试类居然没加public修饰。


全部评论

相关推荐

04-30 21:35
已编辑
长安大学 C++
晓沐咕咕咕:评论区没被女朋友好好对待过的计小将可真多。觉得可惜可以理解,毕竟一线大厂sp。但是骂楼主糊涂的大可不必,说什么会被社会毒打更是丢人。女朋友体制内生活有保障,读研女朋友还供着,都准备订婚了人家两情相悦,二线本地以后两口子日子美滋滋,哪轮到你一个一线城市房子都买不起的996清高计小将在这说人家傻😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务