Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output unit testing results on console using spock junit testing and gradle build system

Tags:

java

gradle

spock

GNU Emacs 24.3.1
Gradle 1.12
spock-core.0.7

Hello,

I am doing unit testing with spock framework using the gradle build system.

When I run my tests gradle test I just see a message like this:

* 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 go and check the xml file to see what exception has been thrown

Is there any option where I could see the exceptions in my console output? For example I have some print message I would like printed to the console output:

    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
    }
}

Many thanks in advance,

like image 624
ant2009 Avatar asked Jun 23 '14 06:06

ant2009


1 Answers

When I run my tests gradle test I just see a message like this: [...]

By default, you'll also see (further up in the output):

  • Which test method(s) failed
  • The exception type
  • The source file and line number where the exception occurred

To see more information, configure Test#testLogging. For example:

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

For further details, check Test in the Gradle Build Language Reference.

Then I have to go and check the xml file to see what exception has been thrown

Typically you would check the HTML report, not the XML file. On Mac you can open the report simply by holding down CMD and double-clicking the file URL after See the report at:. Some *nix terminals offer a similar feature.

like image 190
Peter Niederwieser Avatar answered Oct 19 '22 14:10

Peter Niederwieser