[英]Maven2 compiles my tests, but doesn't run them
I have a simple Maven2 project with tests written for TestNG. 我有一个简单的Maven2项目,其中包含为TestNG编写的测试。 When I say mvn test
Maven2 compiles my test, but don't run them. 当我说mvn test
Maven2编译我的测试,但不运行它们。 I already checked this page: http://maven.apache.org/general.html#test-property-name . 我已经检查了这个页面: http : //maven.apache.org/general.html#test-property-name 。 This is not my case. 这不是我的情况。
Anybody can help? 有人可以帮忙吗?
My directory structure: 我的目录结构:
pom.xml
src
main
java
com ...
test
java
com ...
target
classes <— .class files go there
test-classes <— .class files with tests go there
This is what I see if I run mvn -X test
(end of the log): 如果我运行mvn -X test
(日志结束),这就是我所看到的:
...
[INFO] Surefire report directory: <mydir>/target/surefire-reports
Forking command line: /bin/sh -c cd <mydir> && /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -jar /var/folders/+j/+jAx0g2xGA8-Ns9lWNOWgk+++TM/-Tmp-/surefirebooter7645642850235508331.jar /var/folders/+j/+jAx0g2xGA8-Ns9lWNOWgk+++TM/-Tmp-/surefire4544000548243268568tmp /var/folders/+j/+jAx0g2xGA8-Ns9lWNOWgk+++TM/-Tmp-/surefire7481499683857473873tmp
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.191 sec
I have two tests in the project ( MainTest.java
and FileSetTest.java
). 我在项目中有两个测试( MainTest.java
和FileSetTest.java
)。
My pom.xml
: 我的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.SKIP</groupId>
<artifactId>SKIP</artifactId>
<name>SKIP</name>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<url>http://www.SKIP.com</url>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
<scope>test</scope>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>jsr14</target>
<sourceDirectory>src</sourceDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.SKIP.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The "problem" is somehow related to the fact that you are compiling your tests using the jsr14 target mode which causes the compiler to emit JDK 1.4-compatible bytecode so I think that annotations are removed and TestNG doesn't detect anything to run. “问题”在某种程度上与您使用jsr14目标模式编译测试这一事实有关,这导致编译器发出与JDK 1.4兼容的字节码,因此我认为注释被删除而TestNG没有检测到要运行的任何内容。
My suggestion would be to configure the maven-compiler-plugin to use different compliance level when compiling code code from main and test as shown below: 我的建议是配置maven-compiler-plugin在从main和test编译代码时使用不同的合规级别,如下所示:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>jsr14</target>
</configuration>
<executions>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</execution>
</executions>
</plugin>
I did a quick test, it seems to work. 我做了一个快速测试,似乎工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.