java 我应该用 JUnit 运行什么 GUI(类似于 NUnit gui)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/59128/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:53:02  来源:igfitidea点击:

What GUI should I run with JUnit(similar to NUnit gui)

javaidejunit

提问by

What GUI should use to run my JUnit tests, and how exactly do I do that? My entire background is in .NET, so I'm used to just firing up my NUnit gui and running my unit tests. If the lights are green, I'm clean.

应该使用什么 GUI 来运行我的 JUnit 测试,我该怎么做?我的整个背景都在 .NET 中,所以我习惯于启动我的 NUnit gui 并运行我的单元测试。如果灯是绿色的,我就干净了。

Now, I have to write some Java code and want to run something similar using JUnit. The JUnit documentation is nice and clear about adding the attributes necessary to create tests, but its pretty lean on how to fire up a runner and see the results of those tests.

现在,我必须编写一些 Java 代码并想使用 JUnit 运行类似的东西。JUnit 文档很好地明确了添加创建测试所需的属性,但它非常依赖于如何启动运行程序并查看这些测试的结果。

采纳答案by jjnguy

Eclipse is by-far the best I've used. Couple JUnit with a code coverageplug-in and Eclipse will probably be the best unit-tester.

Eclipse 是迄今为止我用过的最好的。将 JUnit 与代码覆盖率插件相结合,Eclipse 可能是最好的单元测试员。

回答by Grundlefleck

JUnit stopped having graphical runners following the release of JUnit 4.

在 JUnit 4 发布后,JUnit 停止了图形运行器。

If you do have an earlier version of JUnit you can use a graphical test runner by entering on the command line[1]:

如果您确实有早期版本的 JUnit,则可以通过在命令行[1] 上输入来使用图形测试运行器:

java junit.swingui.TestRunner [optional TestClass]

With the optional test class the specified tests will run straight away. Without it you can enter the class into the GUI.

使用可选的测试类,指定的测试将立即运行。没有它,您可以将类输入到 GUI 中。

The benefits of running your tests this way is that you don't have the overhead of an entire IDE (if you're not already running one). However, if you're already working in an IDE such as Eclipse, the integration is excellent and is a lot less hassle to get the test running.

以这种方式运行测试的好处是您没有整个 IDE 的开销(如果您还没有运行)。但是,如果您已经在 Eclipse 等 IDE 中工作,那么集成非常好,并且运行测试的麻烦要少得多。

If you do have JUnit 4, and really don't want to use an IDE to run the tests, or want textual feedback, you can run the text UI test runner. In a similar vein as earlier, this can be done by entering on the command line[1]:

如果您有 JUnit 4,并且真的不想使用 IDE 来运行测试,或者想要文本反馈,您可以运行文本 UI 测试运行器。与前面类似,这可以通过在命令行[1] 上输入来完成:

java junit.textui.TestRunner [TestClass]

Though in this case the TestClass is not optional, for obvious reasons.

尽管在这种情况下 TestClass 不是可选的,原因很明显。

[1] assuming you're in the correct working directory and the classpath has been setup, which may be out of scope for this answer

[1] 假设您位于正确的工作目录中并且已设置类路径,这可能超出此答案的范围

回答by jodonnell

There's a standalone JUnit runner that has a UI, but I recommend using one of the builtin test runners in the Java IDEs (Eclipse, Netbeans, and IntelliJ all have good ones). They all support JUnit, and most support TestNG as well.

有一个具有 UI 的独立 JUnit 运行器,但我建议使用 Java IDE 中的内置测试运行器之一(Eclipse、Netbeans 和 IntelliJ 都有不错的)。它们都支持 JUnit,并且大多数还支持 TestNG。

回答by Antonio

If you want a standalone test runner (not the build-in IDE one), then for Junit3 you can use

如果你想要一个独立的测试运行器(不是内置的 IDE),那么对于 Junit3,你可以使用

  • junit.textui.TestRunner %your_class%- command line based runner
  • junit.swingui.TestRunner [%your_class%]- runner with user interface (swing-powered)
  • junit.textui.TestRunner %your_class%- 基于命令行的跑步者
  • junit.swingui.TestRunner [%your_class%]- 带有用户界面的跑步者(摇摆驱动)

For Junit4, the UI-powered runners were removed and so far I haven't found a convenient solution to run new Junit4 tests on old swing-powered runner without additional libraries. But you can use JUnit 4 Extensionsthat provides a workaround to use junit.swingui.TestRunner. More here

对于 Junit4,UI 驱动的运行器被删除了,到目前为止,我还没有找到一个方便的解决方案来在没有额外库的情况下在旧的 Swing 驱动的运行器上运行新的 Junit4 测试。但是您可以使用JUnit 4 扩展,它提供了使用 junit.swingui.TestRunner 的变通方法。更多在这里

回答by Graviton

Why you need a GUI runner? Can't you just run the tests from the IDE itself?

为什么需要 GUI 运行器?你不能从 IDE 本身运行测试吗?

In .Net we have TestDriven.net, in Java there must be something equivalent. You can check out IntelliJ IDEA, it has the unit testing support built-in.

在 .Net 中我们有TestDriven.net,在 Java 中必须有等价的东西。您可以查看IntelliJ IDEA,它内置了单元测试支持。