2010-05-23 56 views
3

我与TestNG的笔试简单Maven2的项目。当我说mvn test Maven2编译我的测试,但不运行它们。我已经检查了这个页面:http://maven.apache.org/general.html#test-property-name。这不是我的情况。Maven2的编译我的测试,但并不运行它们

有人可以帮忙吗?

我的目录结构:

pom.xml 
src 
    main 
    java 
     com ... 
    test 
    java 
     com ... 
target 
    classes <— .class files go there 
    test-classes <— .class files with tests go there 

这是我所看到的,如果我跑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 

我在项目中的两个测试(MainTest.javaFileSetTest.java) 。

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> 
+0

您的测试课程是以* Test *开始还是结束? – whiskeysierra 2010-05-23 16:24:35

回答

7

“问题”的主题相关的事实,你正在使用这会导致编译器发出JDK 1.4兼容的字节码,所以我觉得jsr14目标模式编译你的测试注释将被删除,并且TestNG不会检测到任何要运行的内容。

我的建议是配置Maven的编译器插件使用编译从主和测试代码的代码时不同的履约水平,如下图所示:

<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> 

我做了一个快速测试,它似乎工作。

+0

非常感谢,这正是我之后的解决方案:) – yegor256 2010-05-24 06:19:44

+0

@Vincenzo不客气。并感谢upvote;) – 2010-05-24 11:14:51

相关问题