Xml Maven的Scalatest:如何标记和过滤整个套件?

Xml Maven的Scalatest:如何标记和过滤整个套件?,xml,scala,maven,scalatest,scala-maven-plugin,Xml,Scala,Maven,Scalatest,Scala Maven Plugin,我有一个Maven项目,我正在使用配置scalatest。我使用的是scalatest 3.0.0,但是我无法标记和过滤整个套件 作为参考,我用过这个博客,但在Maven看来不起作用 我创建了一个新的跳过标记,定义如下: package tags; import java.lang.annotation.*; @org.scalatest.TagAnnotation @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD

我有一个Maven项目,我正在使用配置scalatest。我使用的是scalatest 3.0.0,但是我无法标记和过滤整个套件

作为参考,我用过这个博客,但在Maven看来不起作用

我创建了一个新的跳过标记,定义如下:

package tags;

import java.lang.annotation.*;

@org.scalatest.TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Skip {}
然后,我对我的测试套件进行如下标记:

@tags.Skip
class AcceptanceTest extends FeatureSpec { ... 
<plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <configuration>
        <tagsToExclude>tags.Skip</tagsToExclude>
    </configuration>
    <executions>
        <execution>
            <id>test</id>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>    
然后,我将scalatest maven插件配置如下:

@tags.Skip
class AcceptanceTest extends FeatureSpec { ... 
<plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <configuration>
        <tagsToExclude>tags.Skip</tagsToExclude>
    </configuration>
    <executions>
        <execution>
            <id>test</id>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>    
但是AcceptanceTest套件仍然可以执行。我也尝试过这样标记套件,但没有成功:

class AcceptanceTest extends Tag("tags.Skip") with FeatureSpecLike { ...      

为了分离集成测试的执行,我使用了maven概要文件:

    <profiles>
    <profile>
        <id>default-test</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.scalatest</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <version>1.0</version>
                    <configuration>
                        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        <junitxml>.</junitxml>
                        <filereports>WDF TestSuite.txt</filereports>
                        <tagsToExclude>org.example.testkit.annotations.IntegrationTestSuite</tagsToExclude>
                    </configuration>
                    <executions>
                        <execution>
                            <id>test</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>integration-test</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.scalatest</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <version>1.0</version>
                    <configuration>
                        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        <junitxml>.</junitxml>
                        <filereports>WDF TestSuite.txt</filereports>
                        <tagsToInclude>org.example.testkit.annotations.IntegrationTestSuite</tagsToInclude>
                    </configuration>
                    <executions>
                        <execution>
                            <id>test</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>test</id>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <tagsToInclude>${tagsToInclude}</tagsToInclude>
                <tagsToExclude>${tagsToExclude}</tagsToExclude>
            </configuration>
        </execution>
    </executions>
</plugin>  
要运行单元测试,我运行

mvn test
用于集成测试

mvn test -Pintegration-test
UPD:


我们使用scala 2.11、scalatest 2.2.6、maven 2、java 8。

您可以在不创建新配置文件的情况下动态传递所需的标记:

    <profiles>
    <profile>
        <id>default-test</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.scalatest</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <version>1.0</version>
                    <configuration>
                        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        <junitxml>.</junitxml>
                        <filereports>WDF TestSuite.txt</filereports>
                        <tagsToExclude>org.example.testkit.annotations.IntegrationTestSuite</tagsToExclude>
                    </configuration>
                    <executions>
                        <execution>
                            <id>test</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>integration-test</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.scalatest</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <version>1.0</version>
                    <configuration>
                        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        <junitxml>.</junitxml>
                        <filereports>WDF TestSuite.txt</filereports>
                        <tagsToInclude>org.example.testkit.annotations.IntegrationTestSuite</tagsToInclude>
                    </configuration>
                    <executions>
                        <execution>
                            <id>test</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>test</id>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <tagsToInclude>${tagsToInclude}</tagsToInclude>
                <tagsToExclude>${tagsToExclude}</tagsToExclude>
            </configuration>
        </execution>
    </executions>
</plugin>  
最后,您可以通过以下方式从CLI动态传递标记:

mvn -DtagsToExclude=com.foo.tags.Skip test

有趣的您能更新您的答案并添加IntegrationTestSuite的定义,然后添加scalatest、maven和java版本吗?谢谢!我不得不使用Scala 2.10.x,也许这就是问题所在。。。我必须用Scala 2.11.x测试它