我正在使用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
标志?
答案 0 :(得分:9)
您可以使用exec-maven-plugin
的{{3}}选项,如下所示:
<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