Support for JUnit 5 M4 in IntelliJ IDEA 2017.2
IntelliJ IDEA provides support for the upcoming JUnit 5 release. JUnit has pretty much been the standard for Java unit testing for years, and the latest version brings the library right up to date, making use of Java 8 features and bringing in ways of testing that are familiar if you’ve been using other frameworks like Spock. IntelliJ IDEA 2017.2 adds support for some of these features, to make the experience of testing code as painless and quick as possible.
JUnit 5 supports parameterized tests. These tests let you use the same basic structure of a test with a number of different inputs. This reduces duplication in your test code and also lets you easily add new cases without having to create entire new tests.
IntelliJ IDEA helps you with parameterized tests in a number of different ways, Firstly, it reports “suspicious” use of both
@ParameterizedTest annotations – you only need one of these in order to declare the method is a test.
If you press Alt + Enter on the highlighted
@Test annotation, IntelliJ IDEA suggests removing this unnecessary annotation.
If you’re using the
@ParameterizedTest annotation, you need to supply a source for the parameters, otherwise there are no tests to run. IntelliJ IDEA warns you if you use the
@ParameterizedTest annotation without an associated source (annotations like
If you’re using a source annotation, but it doesn’t match the expectations set by the test method, you’ll also get a warning about this. For example, if you use a
@ValueSource that defines a series of ints as the input, but your test method takes a String parameter, IntelliJ IDEA will warn you that these types don’t match
@MethodSource lets you choose a method that returns a
Stream of values to use for parameters, and IntelliJ IDEA offers suggestions of suitable methods
If you select a method that does not provide the right values for the test method’s arguments, you’ll get a warning about this as well. Here, we’ve given
@MethodSource a method that returns a
Strings, but because our test takes more than one argument we should have chosen a method that returns a
You’ll notice as well that when you provide a method to
@MethodValue, this method is not marked as unused because IntelliJ IDEA recognises it’s used in the annotation.
In addition to this support for parameterized tests, you also get warnings for using the
@Test annotation with
IntelliJ IDEA 2017.2 makes it simple to use all the features in JUnit 5, so that it’s easier and quicker to write effective tests.
Subscribe to Blog updates
Top 10 UI Updates in IntelliJ IDEA for 2023
Hey there, fellow developers! Today, we want to share the most significant UI updates from 2023 that have transformed how IntelliJ IDEA looks and functions. New UI Of course, the highlight of our recent updates was the launch of our new, clean, and modern UI. This was first announced at the en…
The What, Why, and How of JPA Buddy in IntelliJ IDEA
Master JPA entity management with JPA Buddy in IntelliJ IDEA! Our latest article shows you how to simplify your workflow and reduce boilerplate code.
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Import Postman Collections to the HTTP Client
We know that many of you use Postman collections and want to stay in the flow while working with them. This means staying inside IntelliJ IDEA and not switching to a different app. Great news! You can now effortlessly transform Postman collections into .http and use them in the HTTP Client …