简体   繁体   中英

How to make jenkins run integration tests only when deploying to UAT?

I'm using jenkins and I have a staging > qa > uat > master environment set. I don't want jenkins to run any integration tests in staging and qa environments, only for uat and master.

Is it possible to do that? If so, how? I mean, should I separate unit and integration tests in different packages? Today I have:

src/main/java

src/test/java

Define a interface IntegrationTest

    public interface IntegrationTest {}

And use the annotation @Category from Junit4 for categorizing your tests as integraiton test.

@Category(IntegrationTest.class)
public class YourTest

So use the maven surefire and failsafe plugin to create groups of testes.

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <excludedGroups>you.package.IntegrationTest</excludedGroups>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                </includes>
                <groups>you.package.IntegrationTest</groups>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

The Integration test will be automatically excluded from the default execution ie mvn clean package. However, if you run mvn integration-test all the integration tests will run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM