如何配置 Eclipse 以自动运行测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1247174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I configure Eclipse to run your tests automatically?
提问by Boune
I read this article: Configure your IDE to run your tests automatically http://eclipse.dzone.com/videos/configure-your-ide-run-your
我读了这篇文章:配置您的 IDE 以自动运行您的测试 http://eclipse.dzone.com/videos/configure-your-ide-run-your
It's pretty easy to configure Eclipse IDE to run an Ant target every time a file is saved. MyProject -> Right-click : Properties -> Builders -> New -> Ant Builder
配置 Eclipse IDE 以在每次保存文件时运行 Ant 目标非常容易。MyProject -> 右键单击:属性 -> Builders -> 新建 -> Ant Builder
The problem is that the builder has to rebuild the jar on every save, which is very long. The JUnit tests run using the .classes in the jar.
问题是构建器必须在每次保存时重建 jar,这很长。JUnit 测试使用 jar 中的 .classes 运行。
We already have JUnit configurations (EclipseIde .launch files which contains the whole classpath to run the tests). I wish I could create a builder that wraps those JUnit launch files. This would have the benefit of running the tests against Eclipse .classes (faster than rebuilding the jar). Also the test results are displayed in the JUnit view.
我们已经有了 JUnit 配置(EclipseIde .launch 文件,其中包含运行测试的整个类路径)。我希望我可以创建一个包装这些 JUnit 启动文件的构建器。这将有利于针对 Eclipse .classes 运行测试(比重建 jar 更快)。测试结果也显示在 JUnit 视图中。
Has anybody manage to do that?
有没有人设法做到这一点?
采纳答案by Rich Seller
You could try CT-Eclipse, a continuous testing plugin for Eclipse.
您可以尝试CT-Eclipse,这是Eclipse的连续测试插件。
From the plugin page:
从插件页面:
With CT-Eclipse enabled, as you edit your code, Eclipse runs your tests quietly in the background, and notifies you if any of them fail or cause errors.
启用 CT-Eclipse 后,当您编辑代码时,Eclipse 会在后台安静地运行您的测试,并在其中任何一个测试失败或导致错误时通知您。
回答by MatrixFrog
I recently started using Infinitestand it seems to somehow "know" which parts of the code affect which test cases. So when you change some code, it automatically re-runs the tests which are likely to break. If the test fails, it marks an error at the spot where it failed, the same way Eclipse would mark a coding error like calling a non-existent method or whatever. And it all happens in the background without you having to do anything.
我最近开始使用Infinitest,它似乎以某种方式“知道”代码的哪些部分影响了哪些测试用例。因此,当您更改某些代码时,它会自动重新运行可能会中断的测试。如果测试失败,它会在失败的地方标记一个错误,就像 Eclipse 标记编码错误一样,调用不存在的方法或其他什么。这一切都在后台发生,您无需执行任何操作。
回答by Janusz
You can use JUnit Maxit is an eclipse plug in that will run all you tests every time you save. But it will do it without interrupting your work flow. The results are shown in the left corner of Eclipse and you can always go back to the last successful testrun. The plugin runs the tests that are most likely to fail first so that you get a response for your last saving as fast as possible.
您可以使用JUnit Max,它是一个 Eclipse 插件,每次保存时都会运行所有测试。但它不会中断您的工作流程。结果显示在 Eclipse 的左角,您可以随时返回到上次成功的测试运行。该插件首先运行最有可能失败的测试,以便您尽快获得最后一次保存的响应。
回答by vorburger
http://www.junitloop.org/index.php/JUnitLoopis another one like this (haven't tried it yet myself)
http://www.junitloop.org/index.php/JUnitLoop是另一个这样的(我自己还没有尝试过)