2016-03-23 30 views
4

在Eclipse控制台Maven的测试输出:构建是成功的,但没有源编译

[INFO] Scanning for projects... 
    [WARNING] 
    [WARNING] Some problems were encountered while building the effective model for Mabi:Mabi:jar:0.0.1-SNAPSHOT 
    [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.seleniumhq.selenium:selenium-java:jar -> duplicate declaration of version 2.45.0 @ line 20, column 21 
    [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-surefire-plugin @ line 74, column 10 
    [WARNING] 
    [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
    [WARNING] 
    [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
    [WARNING] 
    [INFO]                   
    [INFO] ------------------------------------------------------------------------ 
    [INFO] Building Mabi 0.0.1-SNAPSHOT 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Mabi --- 
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
    [INFO] skip non existing resourceDirectory E:\workspace\Mabi\src\com.TestCase 
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.5:compile (default-compile) @ Mabi --- 
    [INFO] Changes detected - recompiling the module! 
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! 
    [INFO] Compiling 166 source files to E:\workspace\Mabi\target\classes 
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Mabi --- 
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
    [INFO] skip non existing resourceDirectory E:\workspace\Mabi\src\test\resources 
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.5:testCompile (default-testCompile) @ Mabi --- 
    [INFO] No sources to compile 
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ Mabi --- 
    [INFO] No tests to run. 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] BUILD SUCCESS 
    [INFO] ------------------------------------------------------------------------ 
    [INFO] Total time: 7.287 s 
    [INFO] Finished at: 2016-03-23T11:32:40+05:30 
    [INFO] Final Memory: 21M/283M 
    [INFO] ------------------------------------------------------------------------ 

上图显示我的项目的目录,但是当我通过Maven的运行项目它给了我以上结果不经过测试。期待一些准确的解决方案。

这是我的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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>Mabi</groupId> 
    <artifactId>Mabi</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <dependencies> 
    <dependency> 
    <groupId>com.relevantcodes</groupId> 
    <artifactId>extentreports</artifactId> 
    <version>2.40.2</version> 

    </dependency>    
     <dependency>    
      <groupId>org.seleniumhq.selenium</groupId>        
      <artifactId>selenium-java</artifactId>        
      <version>2.45.0</version>        
     </dependency>       
     <dependency>    
      <groupId>org.testng</groupId>        
      <artifactId>testng</artifactId>        
      <version>6.8</version>                 
     </dependency>    
</dependencies> 

    <build> 
    <sourceDirectory>src</sourceDirectory> 

    <resources> 
     <resource> 
     <directory>src/com.TestCase</directory> 
     <includes> 
     <include>**/com.*TestCase.java</include> 
     </includes> 
     </resource>  
    </resources> 

    <plugins> 
     <plugin> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.5</version> 
     <configuration> 
      <source/> 
      <target/> 
     </configuration> 
     </plugin> 
    <plugin> 


     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.19.1</version> 
       <inherited>true</inherited> 
      <configuration> 
       <suiteXmlFile>testng.xml</suiteXmlFile> 
      </configuration> 
    </plugin> 
</plugins> 

</build> 
</project> 
+3

您是否尝试过使用[标准目录布局(https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)? – Biffen

+0

我目前使用的标准方法是src - > test - > java文件 –

+1

按照约定,删除pom文件中的'sourceDirectory'和'resources'条目。测试通常是'* Test.java'和** NOT **'* TestSuite.java'这样的名字,而且如果你使用testng,你很少需要定义一个suiteFile ... surefire插件将处理所有的问题。 。如果这些测试是集成测试,你应该把它们命名为'* IT.java'并且使用maven-failsafe-plugin ...并且遵循名字模式... – khmarbaise

回答

4

Maven是所有关于"convention over configuration"成语。为了使maven-surefire-plugin能够运行你的测试用例,它期望在src/test/java之下找到它,因此,你应该遵循maven的标准目录布局,并把所有的测试用例都放在src/test/java之下。

enter image description here

+0

为我节省了另一个小时的时间\ o/ –

+0

谢谢,我很高兴它帮助! –

相关问题