2

今、私が使用する場合、私はそれを認識しています

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/Benchmark*.java</exclude>
        </excludes>
    </configuration>
</plugin>

実行したくないテストをスキップできます。ただし、特定のプロファイルを使用してビルドすると、上記の除外されたテストが実行される特定のプロファイルが必要です。私はもう試した

<profiles>
    <profile>
        <id>benchmark</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <includes>
                            <include>**/Test*.java</include>
                            <include>**/*Test.java</include>
                            <include>**/*TestCase.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

上記と一緒ですが、うまくいかないようです。

4

2 に答える 2

1

Maven は、期待どおりに上書きするのではなく、構成をマージしているため、プロファイルがアクティブな最終的な構成は次のようになります。

<configuration>
    <includes>
        <include>**/Test*.java</include>
        <include>**/*Test.java</include>
        <include>**/*TestCase.java</include>
    </includes>
    <excludes>
        <exclude>**/Benchmark*.java</exclude>
    </excludes>
</configuration>

これらすべての default は必要ありません<include>とにかく、彼らはすでにそこにいます。<excludes/>基本POMで指定した除外の実行を停止したいことをMavenに伝えるだけです。つまり、プロフィールで次のように言うだけです。

<configuration>
    <excludes/>
</configuration>
于 2013-06-14T04:20:24.973 に答える
1

次のように、プロパティを使用してテスト ソース ディレクトリを定義し、カスタム プロファイルを使用してオーバーライドすることができます。

<properties>
    <test.dir>src/test/java</test.dir>
</properties>

<profiles>
    <profile>
        <id>benchmark</id>
        <properties>
            <test.dir>src/benchmark-tests/java</test.dir>
        </properties>
    </profile>
</profiles>

<build>
    <testSourceDirectory>${test.dir}</testSourceDirectory>
</build>

このように、実行するとsrc/test/javamvn test内ですべてのテストが実行され、 src/benchmark-tests/java内でテストが実行されます。mvn test -Pbenchmark

コンソール出力:

mvn clean test
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running br.com.instaweb.sample.SampleUnitTest
sample unit test was run
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.034 sec

と:

mvn clean test -Pbenchmark
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running br.com.stackoverflow.BenchmarkTest
benchmark test was run
于 2013-06-14T04:15:05.690 に答える