【问题标题】:How can I prevent tests from being run when using exec-maven-plugin使用 exec-maven-plugin 时如何防止运行测试
【发布时间】:2016-10-17 22:40:28
【问题描述】:

我正在使用 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 flag is only honored when using "Surefire, Failsafe and the Compiler Plugin"

问题:我怎样才能使执行取决于skipTests 标志?

【问题讨论】:

  • 我猜你要么将运行 karma 测试包装到一个脚本中,如果设置了 skipTests 属性,然后决定运行 node/karma 命令。另一种解决方案可能是将此配置移动到配置文件中并使用激活:maven.apache.org/pom.html#Activation 或仅在需要时激活它。

标签: maven maven-3 pom.xml exec-maven-plugin


【解决方案1】:

您可以使用exec-maven-pluginskip 选项,如下所示:

<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   

【讨论】:

  • 感谢 exec-maven-plugin 的链接,为我没有先去那里感到羞愧 :) 顺便说一下,它在 1.3 版上运行良好。
猜你喜欢
  • 1970-01-01
  • 2020-10-04
  • 2012-02-11
  • 1970-01-01
  • 2017-08-02
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
  • 1970-01-01
相关资源
最近更新 更多