How to run two profiles in one maven command?

I have a pom.xml file that has a surefire: test plugin and has two profiles to run different test units / tests. I am trying to start them with the command "mvn surefire: test -PfirstProfile, secondProfile". But only the second profile written in the pom.xml is executed here. This command is recommended by the apache maven site. Here is my pom.xml file:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven.plugin.surefire.version}</version>
    <configuration>
      <forkMode>always</forkMode>
      <!-- <testFailureIgnore>true</testFailureIgnore> -->
      <failIfNoTests>false</failIfNoTests>
      <skipTests>${skipTests}</skipTests>
      <runOrder>${testRunOrder}</runOrder>
    </configuration>
    </execution>
    </executions>
  </plugin>
  <profile>
  <id>firstProfile</id>
  <properties>
        <skipTests>false</skipTests>
  </properties>
  <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>${maven.plugin.surefire.version}</version>
              <configuration>
                  <includes>
                    <include>**/AbcTest.java</include>
                  </includes>
              </configuration>
          </plugin>
      </plugins>

  </build>
</profile>
<profile>
  <id>SecondProfile</id>
  <properties>
        <skipTests>false</skipTests>
  </properties>
  <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>${maven.plugin.surefire.version}</version>

              <configuration>
                  <includes>
                      <include>**/xyzTest.java</include>                      
                  </includes>
              </configuration>
          </plugin>
      </plugins>

  </build>
</profile>

      

so how can i combine both of these profiles? I also tried execution IDs. But it doesn't work.

+3


source to share


1 answer


Try changing the configuration for maven-surefire-plugin in both profiles, for example:

   <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>${maven.plugin.surefire.version}</version>
              <configuration>
                  <includes combine.children="append">
                    <include>**/AbcTest.java</include>
                  </includes>
              </configuration>
          </plugin>
      </plugins>

  </build>

      



In addition, it is not recommended to select unit tests by profile. If these tests are integration tests, you should go with the maven failover plugin.

0


source







All Articles