I did google quite a bit; but I could neither find a source saying "of course it is" nor one going "no, it isn't; and here it breaks".
We have about 2000 unit tests of very varying quality, using EasyMock, PowerMock, Mockito; and I am simply wondering: is there a reasonable chance that those 2000 testcases just work when switching to JUnit5; or is that so unlikely that I better not spend a single second trying?
In other words: I am looking for answers that can confirm "yes, it worked for our large code base"; or "no, it is not at all that easy".
As stated by the JUnit 5 User Guide:
Just make sure that the junit-vintage-engine artifact is in your test runtime path. In that case JUnit 3 and JUnit 4 tests will automatically be picked up by the JUnit Platform launcher.
See the example projects in the junit5-samples repository to find out how this is done with Gradle and Maven.
http://junit.org/junit5/docs/current/user-guide/
junit-vintage-engine is for running junit4 or 3 so it looks like it
'JUnit Vintage test engine implementation that allows to run vintage JUnit tests, i.e. tests written in the JUnit 3 or JUnit 4 style, on the new JUnit Platform.'
My current assessment regarding regarding our projects is to stay with JUnit 4.12 for the moment.
As of now, we our build setup is "different" for eclipse and our "backend build"; meaning: we can't use maven/gradle to build within eclipse. And I simply failed to just identify/download the JARs I would need to replace the junit-4.12.jar within our eclipse setup; not even thinking about also providing some (but which) other JARs in order to have JUnit 5 available.
Related
I found instructions on how to start a JUnit 4 test case from within Java, but have been unable to put together constructs that will fire up tests on a JUnit 5 test case.
The JUnit 4 solution I tried was this: How do I run JUnit tests from inside my java application?
I've been trying to get the ConsoleLauncher in JUnit5 to work, but it is throwing exceptions. That was documented here: http://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher
I'd like to automate starting tests to match running a program to simplify the instructions I'm providing when I provide unit tests to students.
Thanks!
If the goal is to simplify a task for students, I think it would be good to use a build tool like Maven or Gradle. This makes it simple to run tests, build their code, etc. JUnit5 tests can be run by using plugins - http://junit.org/junit5/docs/current/user-guide/#running-tests-build.
I had this working 3 day's ago and then since I pulled some code down from me and my buddies git repo, Junit 5 won't work anymore. Like I said, I was able to run Junit unit tests before I pulled from the repo now I can't. Here are print screens with more info.
I have checked the path listed for Junit dependancies and the jar files do exist there. I definitely have Junit on my computer as I had unit tests working before and I did not delete any files since. Any help would be wonderful as I have been wrestling and searching this for some time now.
You should try updating to the latest Intellij 2017.3, as they state that they improved their Junit 5 support.
I am developing a project in Netbeans (8.0.2) that uses JUnit (4.x) for testing application code (in a Netbeans module). In the same module I also have some integration tests. I found a way to separate application code, unit tests and integration tests by putting the latter into a separate folder under MODULE_PATH\test\qa-functional\src. By that, the Netbeans IDE puts those three semantical different kinds of classes into individual folders:
The problem is, my functional tests tend to grow complex, so I would prefer to have them, well, unit tested. However if create a unit test (in the Unit Test Package) for a class of the functional test package, the test does not compile. Seems to be some class path issues.
I know I can put the unit test of the functional test in the functional test package as well (and I will do so if this question does not provide me with some solution), but anyway, is there a way to solve this in Netbeans?
I found a bad solution, changing the order of ant targets in common.xml (in line 610 of NB 8.0.2). But that is obiously not portable, changes with a new version of Netbeans,.. So not really a solution. See details in Netbeans Forum: Classpath problem when unit testing functional tests
In Eclipse, I would simply add a new source folder on the Java build path. But that mechanism does not exist in Netbeans?
For clearification, I added a screenshot.
Thanks in advance for your help.
You are are trying to do a wrong thing:
unit tests should verify the smallest possible functionality, e.g. that a method is producing the expected result
functional tests in NetBeans represent integration tests, tests when you treat the application as a black box
It does not make sense to "unit test" the functionality in the "functional tests". NetBeans treats the tests folders independent so that they are not on each other's classpath, that's why it does not work in NetBeans.
I have a large suite of tests that takes about half an hour to run and would love to be able to the test classes in parallel.
Is there a way to do that with IntelliJ IDEA 9?
IDEA will understand parallel JUnit tests only since version 10.
There is a tracker issue which you can vote for and watch for progress:
http://youtrack.jetbrains.net/issue/IDEA-47103
We plan to add it in IDEA 10, but the priority would depend on the number of votes.
Answering late for posterity.
You can make JUnit tests run in parallel (or serial) to any level of granularity in IntelliJ by changing the Fork mode in the test's run configuration.
Be careful not to confuse this with the Allow parallel run option, which lets you start the test execution multiple times within your IDE.
UPDATE in 2022: This plugin lets you run and debug tests in parallel in IntelliJ IDEA with JUnit4, JUnit5 and TestNG: https://plugins.jetbrains.com/plugin/16229-unit-test-parallel-runner
If you are using JUnit4, you can give this plugin a try:
https://plugins.jetbrains.com/plugin/12959-junit4-parallel-runner
Running tests in parallel is as easy as clicking on the green triangle next to a
class -> all the test methods in the class are run in parallel
package -> all the classes in the package are run in parallel
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.
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.
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
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.
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.
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
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.