junit报错java.lang.Exception: No tests found matching

junit报错java.lang.Exception: No tests found matching

最近在学习Spring的过程中用到了Junit,然而中间遇到了个令人十分捉狂的报错。

1 java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=cdShouldNotBeNull], {ExactMatcher:fDisplayName=cdShouldNotBeNull(soundsystem.CDPlayerTest)], {LeadingIdentifierMatcher:fClassName=soundsystem.CDPlayerTest,fLeadingIdentifier=cdShouldNotBeNull]] from [email protected]
2     at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
3     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
4     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
5     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
6     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
7     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
8     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
9     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

代码如下:

 1 import static org.junit.Assert.*;
 2
 3 import javax.annotation.Resource;
 4
 5 import org.junit.Test;
 6 import org.junit.runner.RunWith;
 7 import org.springframework.test.context.ContextConfiguration;
 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 9
10 @RunWith(SpringJUnit4ClassRunner.class)
11 @ContextConfiguration(classes = CDPlayerConfig.class)
12 public class CDPlayerTest {
13
14     @Resource
15     private CompactDisc cd;
16
17     @Test
18     public void cdShouldNotBeNull(){
19     assertNotNull(cd);
20     }
21
22 }

仔细检查过代码应该是没有什么问题的,上网查了下,发现挺多朋友也遇到过这个坑爹的问题,最后找到解决方案如下。

参考解决方案:

原来除去Junit在代码里需要引用的包以外,如果涉及到需要Spring自动创建的应用上下文,还涉及到另外一个jar包。 
hamcrest-all-1.3.jar 
只要把这个jar包引入即可。 
作者用的Spring版本为4.3.5,Junit版本为4.12。

参考的原作: 
junit报错java.lang.Exception: No tests found matching

原文地址:https://www.cnblogs.com/Allen1994/p/9555132.html

时间: 2024-10-19 00:49:59

junit报错java.lang.Exception: No tests found matching的相关文章

junit报错----java.lang.Exception: No tests found matching

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testSelect], {ExactMatcher:fDisplayName=testSelect(com.vincent.test.UserDaoTest)], {LeadingIdentifierMatcher:fClassName=com.vincent.test.UserDaoTest,fLeadingIdentifier=testSelec

junit test 报错,java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=esopCreateTest],

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=esopCreateTest], {ExactMatcher:fDisplayName=esopCreateTest(com.cmcc.open.ss.util.EsopSynWebServiceActionTest)], {LeadingIdentifierMatcher:fClassName=com.cmcc.open.ss.util.EsopSy

java.lang.Exception: No tests found matching Method deleteById(cn.bytestream.mongodb.MongoDB4CRUDTest)

java.lang.Exception: No tests found matching Method deleteById(cn.bytestream.mongodb.MongoDB4CRUDTest) from [email protected] at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35) at org.eclipse.jdt.internal.junit4.runner.JUni

启动tomcat报错 java.lang.Exception: Socket bind failed

严重: Error initializing endpointjava.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í?? at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:647) at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprPr

反射报错java.lang.IllegalArgumentException: wrong number of arguments

class Person{ private String name ; private String sex ; public Person(){ System.out.println("c"); } public Person(String c1){ this.name =c1; System.out.println("c1"+c1); } public Person(String c1,String c2){ this.name =c1; this.sex =c

Intellij IDEA 报错java.lang.NoClassDefFoundError

Intellij IDEA 报错java.lang.NoClassDefFoundError 11-Aug-2018 23:48:24.686 严重 [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.wbg.testservlet] in context with path [] threw exception [Servle

maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

本篇文章主要介绍了"maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener ",主要涉及到maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener 方面的内容,对于maven web 项目中启动报错jav

报错:java.lang.Long cannot be cast to java.lang.Integer

Long 无法转化成Integer类型. 这个异常 经常出现在hinbernate分页查询的时候. 原因: 这里在Hibernate2.0之前版本list.get(0)返回的是Integer类型. 但是在Hibernate3.0以后版本list.get(0)返回的是Long类型. 解决方法 public Integer getUsersCount() { String hql = "select count(*) from Users"; List list = super.pageQ

开着idea,死机了,关机重启。重启之后,重新打开idea报错java.lang.AssertionError:upexpected content storage modification

开着idea,死机了,关机重启.重启之后,重新打开idea报错java.lang.AssertionError:upexpected content storage modification. goole得到: If you cannot even open your project in IntelliJ: Close IntelliJ Go to the directory <your_home>/.IntelliJIdeaXX/system/cache where XX is your