简体   繁体   English

使用 maven-failsafe-plugin 仅执行部分集成测试子集

[英]Execute only some subset of integration tests with maven-failsafe-plugin

We have a set of integration tests, which all end with IT .我们有一组集成测试,它们都以IT结尾。 Out of those, there is some specific subset, which we would like to execute separately.其中,有一些特定的子集,我们希望单独执行。 Let's say their names end with SpecialIT .假设他们的名字以SpecialIT结尾。 So what we want to achieve is two configurations of the failsafe plugin:所以我们要实现的是 failsafe 插件的两个配置:

  • To execute all tests, ending with IT , but not with SpecialIT -> this is easy.要执行所有测试,以IT结尾,但不以SpecialIT结尾 -> 这很容易。 Just normal inclusion and exclusion by those names.这些名称只是正常的包含和排除。
  • To execute all tests, ending with SpecialIT , but not all others ...IT .执行所有测试,以SpecialIT结尾,但不是所有其他...IT

I thought it would be natural to create some dedicated profile and use a separate failsafe configuration with a negative lookbehind regex for that, so ended up with this configuration (had to use &lt; instead of < , as that one is not allowed there):我认为创建一些专用配置文件并为此使用带有负后视正则表达式的单独故障安全配置是很自然的,所以最终得到了这个配置(必须使用&lt;而不是< ,因为那里不允许那个):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>%regex[.*(?&lt;!Special)IT.*]</exclude>
        </excludes>
        <includes>
            <include>**/*SpecialIT.*</include>
        </includes>
    </configuration>
</plugin>

But when I try to run this - I'm getting the following error:但是当我尝试运行它时 - 我收到以下错误:

Exclamation mark not expected in 'exclusion': %regex[.*(?<!Special)IT.*]

Reading the documentation of the failsafe plugin - I see this:阅读故障安全插件的文档- 我看到了这个:

The syntax in parameter excludes and excludesFile should not use (!).

So the question is: is there any other way to achieve this, without, let's say, renaming all our integration tests into ...StandardIT and ...SpecialIT ?所以问题是:是否有任何其他方法可以实现这一目标,而不是将我们所有的集成测试重命名为...StandardIT...SpecialIT

I was thinking in the direction of tags, test suit names or smth., but in our project we currently have a mix of JUnit5, JUnit4 and Spock (Groovy) tests, so it becomes not so straightforward.我在考虑标签、测试套件名称或 smth. 的方向,但在我们的项目中,我们目前混合使用 JUnit5、JUnit4 和 Spock (Groovy) 测试,因此它变得不那么简单。

PS If I just use this configuration - all IT tests are getting disabled and nothing is executed: PS 如果我只是使用这个配置——所有IT测试都被禁用并且什么都不执行:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*IT.*</exclude>
        </excludes>
        <includes>
            <include>**/*SpecialIT.*</include>
        </includes>
    </configuration>
</plugin>

Thanks to @andrey-b-panfilov, I realized that my problem was that I somehow was under an impression ( based on this ) that all ...IT tests are always executed by default... But this is, of course, only until the <includes> is overwritten.感谢@andrey-b-panfilov,我意识到我的问题是我有一种印象( 基于此)所有...IT测试总是默认执行...但这当然只是直到<includes>被覆盖。 So, the solution is eventually to just define the following two configurations:因此,解决方案最终是只定义以下两个配置:

  • To execute all but SpecialIT :要执行除SpecialIT之外的所有内容:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <includes>
            <include>**/*IT.*</include>
        </includes>
        <excludes>
            <exclude>**/*SpecialIT.*</exclude>
        </excludes>
    </configuration>
</plugin>
  • To execute only SpecialIT :仅执行SpecialIT
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <includes>
            <include>**/*SpecialIT.*</include>
        </includes>
    </configuration>
</plugin>

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

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