Home > Blockchain >  IntelliJ generates java test class in non-standard location
IntelliJ generates java test class in non-standard location

Time:02-19

I have a Spring Boot app using maven as the build tool and I'm working from within IntelliJ IDEA. When I have IntelliJ generate a test from an existing class (Ctl Shift T), IntelliJ puts that test class into the corresponding package under directory src/test, followed by the package name, rather than the maven standard src/test/java.

The source class from which I’m asking IntelliJ to generate a test class is under src/main/java, the standard maven source directory. So I would expect the generated test to end up by default under the corresponding src/test/java location, since that’s the standard maven test directory.

It seems strange to me that IntelliJ would put tests directly under src/test rather than the standard src/test/java. Is there some setting in IntelliJ to specify where the generated classes go?

CodePudding user response:

I ran some tests and it seems the problem arises when you don't already have that test directory location, src/test/java, in your project layout.

If you don't have it already you can create it via the IntelliJ Project Structure panel (Ctrl Alt Shift S, then click Modules).

Also to note, if you open an existing maven project into IntelliJ (File > Open) that already has that standard test library directory in its layout structure, IntelliJ does seem to know to put its generated test classes into that directory.

  • Related