Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决

简介: Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决

报错

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test], {ExactMatcher:fDisplayName=test(com.xqx.dao.BookDao)], {LeadingIdentifierMatcher:fClassName=com.xqx.dao.BookDao,fLeadingIdentifier=test]] from org.junit.internal.requests.ClassRequest@e2144e4
  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:523)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)

异常原因

报错的原因可能有:

1、测试方法的返回类型不是void,或者加了static

2、测试方法有参数。

3、方法没有使用 @Test 注解进行标注。

解决

我是因为加了static导致的报错,去掉static就好啦

测试方法需要满足以下规范:

Junit规范

  • 方法的返回类型必须为void。
  • 方法不能有参数。
  • 方法必须使用 @Test 注解进行标注。

好啦,本篇分享就到此为止!希望你看完本篇文章有所收获,祝你变得更强!!!

目录
相关文章
|
6月前
|
Android开发
复杂项目即时通讯从android 5升级android x后遗症之解决报错#79 java.io.EOFException Unexpected end of ZLIB input stream-优雅草卓伊凡|bigniu
复杂项目即时通讯从android 5升级android x后遗症之解决报错#79 java.io.EOFException Unexpected end of ZLIB input stream-优雅草卓伊凡|bigniu
391 4
复杂项目即时通讯从android 5升级android x后遗症之解决报错#79 java.io.EOFException Unexpected end of ZLIB input stream-优雅草卓伊凡|bigniu
|
5月前
|
Java API 开发工具
【Azure Developer】Java代码实现获取Azure 资源的指标数据却报错 "invalid time interval input"
在使用 Java 调用虚拟机 API 获取指标数据时,因本地时区设置非 UTC,导致时间格式解析错误。解决方法是在代码中手动指定时区为 UTC,使用 `ZoneOffset.ofHours(0)` 并结合 `withOffsetSameInstant` 方法进行时区转换,从而避免因时区差异引发的时间格式问题。
297 3
|
4月前
|
JSON Java 数据格式
java调用服务报错400
java调用服务报错400
124 6
java调用服务报错400
|
4月前
|
JSON Java 数据格式
java调用服务报错415 Content type ‘application/octet-stream‘ not supported
java调用服务报错415 Content type ‘application/octet-stream‘ not supported
292 6
|
8月前
|
人工智能 Java 测试技术
Spring Boot 集成 JUnit 单元测试
本文介绍了在Spring Boot中使用JUnit 5进行单元测试的常用方法与技巧,包括添加依赖、编写测试类、使用@SpringBootTest参数、自动装配测试模块(如JSON、MVC、WebFlux、JDBC等),以及@MockBean和@SpyBean的应用。内容实用,适合Java开发者参考学习。
952 0
|
4月前
|
Java 测试技术 数据库连接
【SpringBoot(四)】还不懂文件上传?JUnit使用?本文带你了解SpringBoot的文件上传、异常处理、组件注入等知识!并且带你领悟JUnit单元测试的使用!
Spring专栏第四章,本文带你上手 SpringBoot 的文件上传、异常处理、组件注入等功能 并且为你演示Junit5的基础上手体验
994 2
|
XML Java 测试技术
Spring5入门到实战------17、Spring5新功能 --Nullable注解和函数式注册对象。整合JUnit5单元测试框架
这篇文章介绍了Spring5框架的三个新特性:支持@Nullable注解以明确方法返回、参数和属性值可以为空;引入函数式风格的GenericApplicationContext进行对象注册和管理;以及如何整合JUnit5进行单元测试,同时讨论了JUnit4与JUnit5的整合方法,并提出了关于配置文件加载的疑问。
Spring5入门到实战------17、Spring5新功能 --Nullable注解和函数式注册对象。整合JUnit5单元测试框架
|
11月前
|
Java 测试技术 Android开发
课时148:junit测试工具
课时148介绍了JUnit测试工具的使用,包括定义、配置和编写测试程序。JUnit是流行的用例测试工具,用于确保代码稳定性。
241 0
|
Java 程序员 测试技术
Java|让 JUnit4 测试类自动注入 logger 和被测 Service
本文介绍如何通过自定义 IDEA 的 JUnit4 Test Class 模板,实现生成测试类时自动注入 logger 和被测 Service。
268 5