2

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

次に、次のようにテスト スイートにタグを付けます。

@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 Tag 除外 CLI 引数が Scaltest に正しく渡されます):

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

2 に答える 2

4

統合テストの実行を分離するために、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 を使用しています。

于 2016-10-12T09:05:32.773 に答える
1

新しいプロファイルを作成せずに、動的に必要なタグを渡すことができます:

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

タグ定義の例:

package com.foo.tags;

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 Skip {}

最後に、次の方法で CLI からタグを動的に渡すことができます。

mvn -DtagsToExclude=com.foo.tags.Skip test
于 2019-11-14T08:56:03.223 に答える