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

后端 未结 5 1704
鱼传尺愫
鱼传尺愫 2020-12-19 02:36

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 tes

相关标签:
5条回答
  • 2020-12-19 02:50

    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.

    0 讨论(0)
  • 2020-12-19 02:55

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

    If you do have an earlier version of JUnit you can use a graphical test runner by entering on the command line[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.

    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.

    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]:

    java junit.textui.TestRunner [TestClass]
    

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

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

    0 讨论(0)
  • 2020-12-19 02:59

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

    • junit.textui.TestRunner %your_class% - command line based runner
    • junit.swingui.TestRunner [%your_class%] - runner with user interface (swing-powered)

    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 Extensions that provides a workaround to use junit.swingui.TestRunner. More here

    0 讨论(0)
  • 2020-12-19 03:07

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

    0 讨论(0)
  • 2020-12-19 03:08

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

    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.

    0 讨论(0)
提交回复
热议问题