【发布时间】:2014-08-18 06:40:01
【问题描述】:
我在尝试使用 Maven 运行 JUnit 测试时遇到问题。对于 Jenkins 插件,我编写了一个测试类。例如:我在文件夹 src/main/java 的包 com.jenkins_plugin 中有类 ConsoleParser。 JUnit 测试用例是文件夹 src/test 中 package com.jenkins_plugin 中的 ConsoleParserTest。为了运行 JUnit 测试,我在 pom 中添加了依赖项:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
然后我在 cmd 中运行了下一个命令:mvn -Dtest=ConsoleParserTest test
问题是我遇到了以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
12:test (default-test) on project swatt_jenkins: No tests were executed! (Set -
DfailIfNoTests=false to ignore this error.) -> [Help 1]
完整的 pom.xml 是:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<finalName>Jenkins_Plugin</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
<inherited>true</inherited>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.526</version>
</parent>
<groupId>Jenkins_Plugin</groupId>
<version>1.0</version>
<packaging>hpi</packaging>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
另外,我必须提到,使用这些设置我成功地运行了测试,但在添加 findbugs 后它崩溃了。因此,我删除了 findbugs 并尝试再次运行测试,但出现了我提到的问题。那么,有人可以解释我必须做什么吗?我尝试添加另一个版本的 JUnit,Surefire,但我遇到了同样的问题,我不明白为什么。
【问题讨论】:
-
你能添加你的testclass的代码吗?
标签: java eclipse maven junit jenkins