2013-12-20 110 views
4

所以目前我有以下的build.gradle文件:查看gradle的junit測試結果?

apply plugin: 'java' 

sourceSets { 
    main { 
     java { 
      srcDir 'src/model' 
     } 
    } 

    test { 
     srcDirs = ["tests/model"] 
    } 
} 

dependencies { 
    compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar') 
    runtime fileTree(dir: 'libs', include: '*.jar') 

    testCompile group: 'junit', name: 'junit', version: '4.+' 
} 

當我輸入「gradle這個測試」進入命令行模式,成功地構建。

按需創建屬性(a.k.a動態屬性),已被棄用:

但是我的Gradle運行測試時,做了以下錯誤。

正如你所看到的,我的junit測試都在文件夾test/model /中,但我想知道如果我的junit測試通過,我該如何看到結果?

你可以在這裏查看我的資料庫:https://github.com/quinnliu/WalnutiQ

+0

如果構建成功,則測試通過。在'build/reports/tests'中生成一個HTML測試報告。你爲什麼不像定義主源代碼那樣定義測試源目錄? –

回答

3

Chingy與,

我不得不更新一兩件事情在你的build.gradle:

源測試
設置添加Maven倉庫獲得的JUnit庫

apply plugin: 'java' 

repositories { 
    mavenCentral() 
} 

sourceSets { 
    main { 
     java { 
      srcDir 'src/model' 
     } 
    } 

    test { 
     java { 
      srcDir 'tests/model' 
     } 
    } 
} 

dependencies { 
    compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar') 
    runtime fileTree(dir: 'libs', include: '*.jar') 

    testCompile group: 'junit', name: 'junit', version: '4.+' 
} 

現在,結果$ gradle build

bender:WalnutiQ demo$ gradle build 
:compileJava UP-TO-DATE 
:processResources UP-TO-DATE 
:classes UP-TO-DATE 
:jar UP-TO-DATE 
:assemble UP-TO-DATE 
:compileTestJava 
Note: Some input files use unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details. 
:processTestResources UP-TO-DATE 
:testClasses 
:test 

model.RetinaTest > test_seeBMPImage FAILED 
    java.lang.IllegalArgumentException at RetinaTest.java:25 

model.MARK_I.SpatialPoolerTest > test_performSpatialPoolingOnRegion FAILED 
    java.lang.IllegalArgumentException at SpatialPoolerTest.java:60 

model.util.JsonFileInputOutputTest > test_saveRegionObject FAILED 
    java.lang.IllegalArgumentException at JsonFileInputOutputTest.java:69 

model.util.SynapsePermanencesViewerTest > test_saveRegionToBeOpenedInSynapsePermanencesViewer FAILED 
    java.lang.IllegalArgumentException at SynapsePermanencesViewerTest.java:45 

49 tests completed, 4 failed 
:test FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':test'. 
> There were failing tests. See the report at: file:///Users/demo/development/tmp/WalnutiQ/build/reports/tests/index.html 

我想你可以把它從這裏:O)

PS:我會建議重構你的項目結構匹配的Maven /搖籃結構,所以你不必處理源組和它會讓你的build.gradle更清晰。

src/main/java Production Java source 
src/main/resources Production resources 
src/test/java Test Java source 
src/test/resources Test resources 
src/sourceSet/java Java source for the given source set 
src/sourceSet/resources Resources for the given source set 
+0

非常感謝你! –

3

當您運行gradle buildgradle test,有可能創建一個build目錄。 此目錄是放置所有構建工件的位置。 build目錄內是reports目錄。該目錄是報告的放置位置。 例如,pmd報告,junit報告等。

JUnit報告位於tests目錄中。在瀏覽器中打開index.html文件以查看報告。

2

您可以在測試塊中指定JUnit測試結果的位置,並使用以下命令。

test { 
    reports.junitXml.destination = file('build/test-results/folder') 
}