我正在向 Maven 添加基于 Karma 的 JS 单元测试。我使用了以下配置:
<plugin>
<groupId>com.kelveden</groupId>
<artifactId>maven-karma-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>start</goal>
</goals>
</execution>
</executions>
<configuration>
<browsers>Chrome</browsers>
</configuration>
</plugin>
当我使用 时,测试在我的机器上单独工作(没有 Maven)karma start karma.conf.js
,但是使用 Maven 我得到了以下错误:
[ERROR] Failed to execute goal com.kelveden:maven-karma-plugin:1.0:start (default)
on project web: There was an error executing Karma. Cannot run program "karma":
CreateProcess error=2, The system cannot find the file specified -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
com.kelveden:maven-karma-plugin:1.0:start (default) on project web:
There was an error executing Karma.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
...
Caused by: java.io.IOException: Cannot run program "karma": CreateProcess error=2,
The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at com.kelveden.karma.StartMojo.createKarmaProcess(StartMojo.java:151)
... 22 more
Caused by: java.io.IOException: CreateProcess error=2,
The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 23 more
这就是我觉得有点奇怪的原因:根据这个 class,karma.conf.js
应该默认找到 (@Parameter(defaultValue = "${basedir}/karma.conf.js", property = "configFile", required = true)
)。另外,我尝试在-DconfigFile=...
参数中传递绝对和相对路径,它不起作用。我使用Windows,但我认为这应该不是问题。我不确定配置中到底有什么问题,不胜感激。