How to make IntelliJ use the failsafe argline instead of the surefire one?
Answered
How do I make IntelliJ aware, that a test is an integration test? The problem is, in my pom file there are different configuration of argLine for the surefire and failsafe plugin. For my integration test, IntelliJ is picking up the surefire one, and the test fails. I want to somehow signal to IntelliJ, that this is an integration test and it should pick up the failsafe argLine.
In IntelliJ options I see in “Running tests”, that IntelliJ is aware of both surefire and failsafe, but I don't know, how IntelliJ picks which one to use, when I right-click on the test file and select “Run TestNameIT”.
Please sign in to leave a comment.
Piotr Gliźniewicz Can you share a minimal sample project for this problem and we'll do some analysis on it?
This one actually exhibits the opposite behavior, it always loads the “failsafe” argLine, but I couldn't quickly replicate the peculiarity of my project, that triggers using the “surefire” argline for our integration tests. Nevertheless, it shows, that IntelliJ is picking the wrong argline.
https://github.com/pglizniewicz/intellijtest/blob/main/src/test/java/pl/glizniewicz/intellijtest/IntellijtestApplicationTests.java
If you just mvn clean install, it will run fine, maven uses its argLine as expected. But in IntelliJ (2023.3) the IntellijtestApplicationTests fail, because it will load the failsafe argline.
Reproduced under both IDEA 2023.2.5 and 2023.3. I'll create an issue for this. Run with
./mvnw test
or in the Maven tool window with test task all works well.Before fire the issue, I'd like to share the behavior in IDEA, it simples add all <argLine> tag values in pom.xml to the run command:
<argLine>-DtestProperty=surefire</argLine>
<argLine>-DtestProperty=failsafe</argLine>
java -ea -DtestProperty=surefire -DtestProperty=failsafe … com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 pl.glizniewicz.intellijtest.IntellijtestApplicationTests
So you may try this workaround:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<argLine>-Dsurefire=true</argLine>
</configuration>
</plugin>
Then:
@Test
void contextLoads() {
// given surefire configuration
// when
assertThat(System.getProperty("surefire"))
// then
.isEqualTo("true");
}