Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: activate Maven profile when running Junit tests

I have declared some properties that are specific to Maven profiles. A part of my pom.xml:

<profiles>
            <profile>
                <id>release</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <my.properties.file>foo.xml</my.properties.file>
                </properties>
            </profile>
            <profile>
              <id>ci</id>
              <properties>
                <my.properties.file>bar.xml</my.properties.file>
              </properties>
        </profile>
</profiles>

I encounter some problem to use the "ci" Maven profile when I start Junit tests via IntelliJ IDEA 2016.
I activate my profile via the "Maven Projects" panel, then I start tests. The problem is the "my.properties.file" property value is equal to "foo.xml", not "bar.xml".

I have no problem with command-line (I can use the "-Pci" flag). How can I tell IntelliJ to use the "ci" profile? Thx.

like image 371
Jonathan Lermitage Avatar asked May 13 '16 09:05

Jonathan Lermitage


People also ask

How does Maven run test cases in IntelliJ?

Run testsOpen the Maven tool window. Under the Lifecycle node select test. Note that goals specified in the Maven surefire plugin will be activated at this phase and all tests in a project or in a module will be run.

How does Maven integrate with JUnit?

The Maven Surefire Plugin 2.22. 0 (or newer) provides native support for JUnit 5. If we want to use the native JUnit 5 support of the Maven Surefire Plugin, we must ensure that at least one test engine implementation is found from the classpath. We can run our unit tests by using the command: mvn clean test.


1 Answers

You should add the profiles to the Maven setting.xml file (you should find it in the path ${YOUR_MAVEN_HOME}\apache-maven-3.1.1\conf\setting.xml). Then, you have to open intellij, click on View > Tool Windows > Maven Projects. There, you should see your profiles (ci and release) and select the correct one.

Hope this can help you.

like image 190
ervidio Avatar answered Oct 14 '22 21:10

ervidio