Spring Testing Improvements in IntelliJ IDEA 2017.1
In the last post we talked about Spring Data improvements, but it doesn’t stop there. IntelliJ IDEA 2017.1, released last week, has enhanced support for testing using the Spring framework.
Gutter Icons and Navigation
You’ll see that where you use the standard test annotations, you have gutter icons to help you to navigate around the code, the same as you’d usually expect from Spring annotations. For example, you can see and navigate to the relevant application contexts, and navigate to the declarations of autowired beans.
And of course IntelliJ IDEA recognises classes annotated with Spring test annotations as a test that can be run.
These screenshots show the functionality working for @RestClientTest, but it applies equally to @JsonTest, @DataJpaTest, @WebMvcTest, @WebIntegrationTest, and so on, including your own custom tests.
IntelliJ IDEA also understand mocks, and how they work in Spring tests. Gutter icons take you to the declaration of the mock.
You can easily work with WebAppConfiguration with the provided navigation and code completion.
There’s also support for test property sources, and meta annotations for properties. For example, you get code completion for
@TestPropertySource and navigation to the properties file.
Even if you declare your own TestProperties annotation and alias the TestPropertySource attributes, code completion and navigation still works as expected.
Another place where completion and navigation are provided is in the
@Sql annotation. Here, IntelliJ IDEA offers suggestions, and can even show you when you’ve configured something incorrectly.
Inspections have been added to help catch problems that arise from using the wrong attributes on
@DirtiesContext. For example, if you set the methodMode at the class level, you’ll see a warning.
Similarly for setting hierarchy mode when it’s not applicable
And also for using classMode at the method level
More new inspections show where the method signature doesn’t match the annotation’s expectations. For example, if you have a return type on a method annotated with either
Or if your
@AfterTransaction methods take arguments.
In summary, IntelliJ IDEA 2017.1 makes testing Spring applications even easier, with inspections, code completion, and easy navigation.
Develop with Pleasure!
Subscribe to Blog updates
Thanks, we've got you!