2017-04-14 141 views
0

我有一个来自maven任务的调用单元测试的问题。我pom.xml如何运行测试maven?

<?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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>FizzBuzzTDDKata</groupId> 
    <artifactId>FizzBuzzTDDKata</artifactId> 
    <version>1.0-SNAPSHOT</version> 


    <dependencies> 
     <!-- https://mvnrepository.com/artifact/org.junit/junit5-engine --> 
     <dependency> 
      <groupId>org.junit</groupId> 
      <artifactId>junit5-engine</artifactId> 
      <version>5.0.0-ALPHA</version> 
      <scope>test</scope> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all --> 
     <dependency> 
      <groupId>org.mockito</groupId> 
      <artifactId>mockito-all</artifactId> 
      <version>1.9.5</version> 
      <scope>test</scope> 
     </dependency> 

    </dependencies> 
</project> 

我想补充一些根据教程<scope>财产,但仍当我尝试使用mvn clean install或“MVN测试”我:

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec 

Results : 

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.950s 
[INFO] Finished at: Fri Apr 14 16:12:32 CEST 2017 
[INFO] Final Memory: 11M/184M 
[INFO] ------------------------------------------------------------------------ 

我使用的IntelliJ IDEA 2016年2月5日Ultimate和每个Maven任务都作为Intellij中的运行配置运行。我究竟做错了什么?我应该添加一些其他的依赖关系,建立到pom.xml

回答

0

首先你需要在Junit5 User Guide描述

<build> 
<plugins> 
    ... 
    <plugin> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19</version> 
     <dependencies> 
      <dependency> 
       <groupId>org.junit.platform</groupId> 
       <artifactId>junit-platform-surefire-provider</artifactId> 
       <version>1.0.0-M4</version> 
      </dependency> 
     </dependencies> 
    </plugin> 
</plugins> 

添加到您的pom.xml的。你必须定义一个TestEngine,它也在链接中描述。

<build> 
<plugins> 
    ... 
    <plugin> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19</version> 
     <dependencies> 
      <dependency> 
       <groupId>org.junit.platform</groupId> 
       <artifactId>junit-platform-surefire-provider</artifactId> 
       <version>1.0.0-M4</version> 
      </dependency> 
      <dependency> 
       <groupId>org.junit.jupiter</groupId> 
       <artifactId>junit-jupiter-engine</artifactId> 
       <version>5.0.0-M4</version> 
      </dependency> 
     </dependencies> 
    </plugin> 
</plugins> 

... ... org.junit.jupiter 的JUnit木星-API 5.0.0-M4 测试

这应该是所有的。

+0

不幸的是,这也帮不了我。 – Ice

+0

我知道的一个常见问题是,Test类没有被命名为* Test.java或Test * .java。你是怎么命名的? –

+0

测试类被命名为'FizzBu​​zzTest.java'。 – Ice