使用exec-maven-plugin时如何防止测试运行 [英] How can I prevent tests from being run when using exec-maven-plugin

查看:120
本文介绍了使用exec-maven-plugin时如何防止测试运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用exec-maven-plugin在maven项目中运行JavaScript单元测试

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>run-karma</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>${node.bin.folder}/node</executable>
                <workingDirectory>${project.basedir}</workingDirectory>
                <arguments>
                    <argument>node_modules/karma/bin/karma</argument>
                    <argument>start</argument>
                    <argument>--single-run</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

我以为如果我通过了-DskipTests,将跳过整个测试阶段,但事实并非如此,时被接受

问题:如何使执行取决于skipTests标志?

您可以使用exec-maven-plugin的rel ="noreferrer"> skip 选项如下:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <executions>
                <execution>
                    <id>run-karma</id>
                    <phase>test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>cmd</executable>
                        <arguments>
                            <argument>/C</argument>
                            <argument>echo</argument>
                            <argument>hello</argument>
                        </arguments>
                        <skip>${skipTests}</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

请注意${skipTests}的用法作为其值的一部分.还要注意,我使用了推荐的新版本1.5.0.

运行:

mvn clean test -DskipTests

输出将包含:

[INFO] Tests are skipped.   
[INFO]   
[INFO] --- exec-maven-plugin:1.5.0:exec (run-karma) @ sample-project ---   
[INFO] skipping execute as per configuration   
[INFO] ------------------------------------------------------------------------   
[INFO] BUILD SUCCESS   

执行时:

mvn clean test

输出应为

Tests run: 8, Failures: 0, Errors: 0, Skipped: 0   

[INFO]   
[INFO] --- exec-maven-plugin:1.5.0:exec (run-karma) @ sample-project ---   
hello   
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS   

I am running JavaScript unit tests in a maven project using exec-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>run-karma</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>${node.bin.folder}/node</executable>
                <workingDirectory>${project.basedir}</workingDirectory>
                <arguments>
                    <argument>node_modules/karma/bin/karma</argument>
                    <argument>start</argument>
                    <argument>--single-run</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

I was under the assumption that if I passed -DskipTests, the entire test phase would be skipped but that's not the case, the skipTests flag is only honored when using "Surefire, Failsafe and the Compiler Plugin"

Question: How can I make that execution depend on the skipTests flag?

解决方案

You can use the skip option of the exec-maven-plugin as following:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <executions>
                <execution>
                    <id>run-karma</id>
                    <phase>test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>cmd</executable>
                        <arguments>
                            <argument>/C</argument>
                            <argument>echo</argument>
                            <argument>hello</argument>
                        </arguments>
                        <skip>${skipTests}</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Note the usage of ${skipTests} as part of its value. Also note I used a newer version, 1.5.0, recommended.

Running:

mvn clean test -DskipTests

The output would contain:

[INFO] Tests are skipped.   
[INFO]   
[INFO] --- exec-maven-plugin:1.5.0:exec (run-karma) @ sample-project ---   
[INFO] skipping execute as per configuration   
[INFO] ------------------------------------------------------------------------   
[INFO] BUILD SUCCESS   

While executing:

mvn clean test

The output would be

Tests run: 8, Failures: 0, Errors: 0, Skipped: 0   

[INFO]   
[INFO] --- exec-maven-plugin:1.5.0:exec (run-karma) @ sample-project ---   
hello   
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS   

这篇关于使用exec-maven-plugin时如何防止测试运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆