2017-04-14 238 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