Referencing Test Classes in Another IntelliJ Module

When I added MVC to my Spring-Data app I structured the project into two modules: JPA and MVC, wiring them as a single Spring Boot Application. You can read about it here. There were some test utility methods in the JPA module that I wanted to re-use in my MVC Controller tests. Referencing JPA Java Source from my MVC tests was a non-issue, but referencing the JPA Test Source wasn't as straightforward.

When referencing the JPA Module methods in my MVC Module tests IntelliJ Intellisense found the JPA Module Utility Class just fine, but Gradle wouldn't build the MVC Test Classes.

Here's how to reference the test source in a separate IntelliJ Module. Add the referenced project's test source output to your module's dependencies in the its build.gradle. In my case, I'm adding the JPA test output to my MVC Module build.gradle. IntelliJ will give you a “cannot infer argument types” warning, but will work fine regardless. If you don't want to see the warning you can add a //noinspection check as you see below.

The source code referenced in this post can be found in the v0.1.2 branch of my Spring-Data app on GitHub.

Posted June 09, 2015 11:51 AM EDT

More Like This Post