Java – use Spock JUnit test and gradle to build the system and output unit test results on the console

GNU Emacs 24.3.1
GNU Emacs 24.3.1
Gradle 1.12
spock-core.0.7

Hello,

I am using gradle to build the system and Spock framework for unit testing

When I run my gradle test, I only see this message:

* What went wrong:
Execution Failed for task ':test'.
> There were failing tests. See the report at: file:///home/projs/gradleTest/build/reports/tests/index.html

Then I have to check the XML file to see what exceptions are thrown

Is there an option where I can see exceptions in the console output? For example, I have some print messages that I want to print to the console:

catch(FileNotFoundException ex) {
        System.out.println("Exception " + ex.toString());
    }
    catch(IOException ex) {
        System.out.println("Exception " + ex.toString());
    }
    catch(Exception ex) {
        System.out.println("Exception " + ex.toString());
    }

My gradle build file:

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

repositories {
              mavenLocal()
              mavenCentral()
}
dependencies {
             compile "com.googlecode.json-simple:json-simple:1.1.1"
             testCompile "org.codehaus.groovy:groovy:2.3.3"
             testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}

My Spock unit test:

import spock.lang.Specification;
class SnapClientTest extends Specification {
    def "Request from web services"() {
        given:
        SnapClient snapclient = new SnapClient()

        expect:
        snapclient.makeRequest() == 0
    }
}

Thank you in advance,

Solution

By default, you will also see (further in the output):

>Which test method failed > exception type > source file and line number of exception

To see more information, configure test#testlogging For example:

tasks.withType(Test) {
    testLogging {
        exceptionFormat "full"
    }
}

For more details, see the tests in the gradle build language reference

Typically, you will examine HTML reports instead of XML files On MAC, simply press and hold CMD and double-click the file URL after viewing the report location to open the report Some * Nix terminals provide similar functions

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>