2014-09-28 58 views
0

我在用groovy編寫的JUnit測試代碼中執行了一些命令,但命令的輸出未顯示在gradle測試報告中。有誰知道爲什麼發生這種情況?命令的輸出不顯示在gradle測試報告的標準輸出中

以下是我的簡化代碼:

package org.myorg.myapp 

import org.apache.commons.exec.CommandLine 
import org.apache.commons.exec.DefaultExecutor 
import org.junit.Test 

class MyTest { 

    @Test 
    void executelsCommand() { 
    println("Started.") 

    String line = "ls" 
    CommandLine cmdLine = CommandLine.parse(line) 
    DefaultExecutor executor = new DefaultExecutor() 
    int exitValue = executor.execute(cmdLine) 

    println("Finished.") 
    } 

} 

的build.gradle:

apply plugin: 'java' 
apply plugin: 'groovy' 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'org.codehaus.groovy:groovy-all:2.3.3' 
    testCompile 'org.apache.commons:commons-exec:1.2' 
    testCompile 'junit:junit:4.11' 
} 

test { 
    testLogging.showStandardStreams = true 
} 

執行上面的代碼的結果如下:

The result of executing the above code

如果我執行上面的代碼在我的eclipse中使用Run As - > JUnit Te st,ls命令的輸出成功顯示在控制檯窗口中。

ls command's output shows up in the Console window

回答

2

在構建腳本中添加:

test { 
    testLogging.showStandardStreams = true 
} 
+0

謝謝你的答案,但它不工作。我用build.gradle編輯了我的問題。 – 2014-09-29 12:43:52

相關問題