xml - 来自 Maven 的 Scalatest : How to tag and filter out an entire Suite?

标签 xml scala maven scalatest scala-maven-plugin

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

作为引用,我使用了博客Tag a whole ScalaTest suite (update for Java 8)但这似乎不适用于 Maven。

我创建了一个新的 Skip 标签,定义如下:

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 { ... 

然后我像这样配置我的 scalatest-maven-plugin:

<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>    

然后运行 ​​mvn clean install -X 我看到了(它正确地将 -l 标签排除 CLI 参数传递给 Scalatest):

[DEBUG] Forking ScalaTest via: cmd.exe /X /C "java -Dbasedir=mydir 
        org.scalatest.tools.Runner -R -l tags.Skip ...

但是 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>

然后我相应地标记了集成测试

@IntegrationTestSuite
class ExampleTest extends PropSpec with MockitoSugar with BeforeAndAfterAll with EndpointTestHelper {

运行我运行的单元测试

mvn test

用于集成测试

mvn test -Pintegration-test

更新:

package org.example.testkit.annotations;

import org.scalatest.TagAnnotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface IntegrationTestSuite {}

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

关于xml - 来自 Maven 的 Scalatest : How to tag and filter out an entire Suite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39993622/

相关文章:

xml - XSLT 与 LaTeX

c++ - XML 解析器包装器

maven - 如何配置 grails 2.4.0 以通过身份验证解析来自 JFrog Artifactory 的 Artifact ?

java - Maven - 如何管理具有共同依赖项的多个 jar

Java:使用哪个配置框架?

xml - XPath比较 child 的值和 parent 的属性

arrays - 如何在Postgresql中插入具有列数组<array<double>>的数据框?

python - 为什么当我将 wholeTextFiles() 与 pyspark 一起使用时 AWS 拒绝我的连接?

scala - 对 future/并行代码有用的堆栈跟踪

java - GMavenPlus - 如何在 gmavenplus-plugin 执行的脚本中获取 Maven 属性值