简体   繁体   English

如何让 jenkins 仅在部署到 UAT 时运行集成测试?

[英]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.我正在使用 jenkins 并且我有一个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.我不希望 jenkins 在暂存和质量检查环境中运行任何集成测试,仅针对 uat 和 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定义接口 IntegrationTest

    public interface IntegrationTest {}

And use the annotation @Category from Junit4 for categorizing your tests as integraiton test.并使用 Junit4 中的注释@Category将您的测试分类为集成测试。

@Category(IntegrationTest.class)
public class YourTest

So use the maven surefire and failsafe plugin to create groups of testes.因此,请使用 maven surefirefailsafe插件来创建睾丸组。

        <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.集成测试将自动从默认执行中排除,即 mvn clean package。但是,如果您运行mvn integration-test ,所有集成测试都将运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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