Sky*_*ker 2 xml scala maven scalatest scala-maven-plugin
我有一个 Maven 项目,我正在使用scalatest-maven-plugin来配置 scalatest。我正在使用 scalatest 3.0.0,但是我无法标记和过滤整个套件。
作为参考,我使用了博客标记整个 ScalaTest 套件(Java 8 的更新),但这似乎不适用于 Maven。
我创建了一个新Skip标签,定义如下:
package tags;
import java.lang.annotation.*;
@org.scalatest.TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Skip {}
Run Code Online (Sandbox Code Playgroud)
然后我像这样标记我的测试套件:
@tags.Skip
class AcceptanceTest extends FeatureSpec { ...
Run Code Online (Sandbox Code Playgroud)
然后我像这样配置我的 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>
Run Code Online (Sandbox Code Playgroud)
然后运行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 ...
Run Code Online (Sandbox Code Playgroud)
但该AcceptanceTest套件仍然被执行。我也尝试过像这样标记套件但没有成功:
class AcceptanceTest extends Tag("tags.Skip") with FeatureSpecLike { ...
Run Code Online (Sandbox Code Playgroud)
为了单独执行集成测试,我使用了 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>
Run Code Online (Sandbox Code Playgroud)
然后我相应地标记了集成测试
@IntegrationTestSuite
class ExampleTest extends PropSpec with MockitoSugar with BeforeAndAfterAll with EndpointTestHelper {
Run Code Online (Sandbox Code Playgroud)
运行我运行的单元测试
mvn test
Run Code Online (Sandbox Code Playgroud)
用于集成测试
mvn test -Pintegration-test
Run Code Online (Sandbox Code Playgroud)
更新:
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 {}
Run Code Online (Sandbox Code Playgroud)
我们使用 scala 2.11、scalatest 2.2.6、maven 2、java 8。