Add two flags in Maven tag to SkipTests

paul :

I´m using a ScalaTest plugin to execute some IT test. I need to skip all the test(Unit, IT) in some pipelines, and they only use the flag ${skipTests} so I need to use that flag for all my types of testing. In local sometimes I want just to execute, unit or IT test, but now having only one flag it´s not possible.

Only comment the line in the plugin of the IT it would works but I dont like this error prone aproach(Someone will commit the comment line for sure)

                <skipTests>${skipTests}</skipTests>

I was thinking that it would be great if I can use some sort of OR condition to set a new flag in my local executions as true and keep the other as false

            <skipTests>${skipTests} || ${skipItTests}</skipTests>

Obviously this is not working, but I was wondering if someone know a way to do what I want.

Regards.

Павлухин Иван :

It has been already answered in Prevent unit tests but allow integration tests in Maven

At glance you can use following pom snippet for being able running any combination of (UNIT, IT) tests.

<project>
  ...
  <properties>
    <skipTests>false</skipTests>
    <skipITs>${skipTests}</skipITs>
    <skipUTs>${skipTests}</skipUTs>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.12.4</version> <!-- use appropriate version -->
        <configuration>
          <skipTests>${skipTests}</skipTests>
          <skipITs>${skipITs}</skipITs>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version> <!-- use appropriate version -->
        <configuration>
          <skipTests>${skipUTs}</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

And use

  • mvn install -DskipUTs : Skips Unit tests
  • mvn install -DskipITs : Skips Integration tests
  • mvn install -DskipTests : Skips both Unit and Integration Tests

Original post is https://antoniogoncalves.org/2012/12/13/lets-turn-integration-tests-with-maven-to-a-first-class-citizen/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=150786&siteId=1
Recommended