JUnit 无法在 Eclipse 中找到测试
我在 Eclipse 3.5 中的 JUnit 4 测试中遇到了一个奇怪的问题,我无法解决 - 非常感谢收到的任何提示!
最初:我有一个正常工作的测试套件,其中 100 多个测试均配置了 JUnit 4 注释。我通常通过右键单击源文件夹并选择“作为 JUnit 测试运行”来运行它们。一切都很顺利。
现在:当我尝试运行测试消息时,我得到的只是一个错误“未使用测试运行程序‘JUnit 4’找到测试”。
知道发生了什么吗?我根本无法弄清楚可能发生了什么变化导致这次失败。
我的猜测是,这是基于构建路径或类路径的一些配置问题?
I have a strange issue with JUnit 4 tests in Eclipse 3.5 that I couldn't solve - any hints gratefully received!
Initially: I had a test suite working properly, with 100+ tests all configured with JUnit 4 annotations. I'd run these typically by right clicking on my source folder and selecting "Run as JUnit test". All worked perfectly.
Now: When I try to run the test messages all I get is an error "No tests found with test runner 'JUnit 4'".
Any idea what is happening? I simply can't work out what could have changed to make this fail.
My guess is that it is some configuration issue based on the build path or class path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也有这个问题,执行“项目 --> Clean”,然后尝试像往常一样运行单元测试已经做到了!
Had this issue too, doing a "Project --> Clean" and then trying to run the unit tests as usual already did it!
我以不同的方式解决了这样的问题。这些解决方案都不适合我。我的项目是一个 Google Web App 项目、一个 Maven 项目和一个 JREbel 项目...所以其中任何一个都可能会扰乱我的设置。
我还发现我无法使用 Run As -> 来运行带有 main() 方法的任何类。 Java 应用程序。这导致了 ClassNotFoundException。
我的解决方案是创建一个新的 Web 应用程序项目并复制所有源代码并再次设置。现在 Java 应用程序和 JUnit 测试都按预期工作
I solved a problem like this differently. None of these solutions worked for me. My project is a Google Web App project, a Maven Project, and a JREbel project... so any of these could have been messing with my setup.
I also found that I could not run any classes with a main() method using Run As -> Java Application. That resulted in a ClassNotFoundException.
My solution was to create a new Web Application Project and copy in all the source and set it up again. Now both Java Application and JUnit Test work as expected
我的前几个想法(没有看到一些示例测试代码):
没有测试使用测试运行程序“JUnit 4”发现
很多建议都要求重新启动 Eclipse 并清理项目。根据我的经验,有时 Eclipse 会陷入一种模式,它认为我正在尝试在 JUnit 3 和 4 之间进行混合运行,因此有时会使用命名为“test...”的旧用语来命名“@Test”方法。作品。
另外,如果您有任何其他插件,即 m2eclipse 或您最近添加的其他插件,这也可能会影响您的情况。如果您最近添加的任何内容使用其自己的 JUnit 版本,则可能会导致问题。
一些示例测试代码可能有助于进一步调查。
My first couple of thoughts (without seeing some example test code):
No tests found with test runner 'JUnit 4'
A lot of suggestions state to restart Eclipse and clean project. In my experience, sometimes eclipse gets stuck in a mode where it thinks I am trying to do a hybrid run between JUnit 3 and 4, so naming the '@Test' method with the old verbiage of naming it 'test...' sometimes works.
Also if you have any other plugins, i.e. m2eclipse, or other that you have recently added, this could effect your situation as well. If anything you have recently added uses its own version of JUnit, this could cause issues.
Some sample test code, might help with further investigation.
这个问题最有趣的答案。
更改测试名称以“test”开头
例如
@Test
public void checkForTwoStringTest(){....}
更改为
@Test
public void testCheckForTwoString
这确实像一个奇迹......:-)
funniest answer for this question.
Change the test name to start with "test"
For example,
@Test
public void checkForTwoStringTest(){....}
Change to
@Test
public void testCheckForTwoString
This did work like a miracle.... :-)
我一直没有找到这个问题的真正原因,但升级到 Eclipse 3.6 最终解决了这个问题。
I never found out the real cause of this issue but an upgrade to Eclipse 3.6 finally solved it.