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

2

6
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,

Newland answered 23/6, 2014 at 6:58 Comment(1)
See Test#testLogging in the Gradle Build Language Reference.Lessielessing
L
16

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.

Lessielessing answered 24/6, 2014 at 14:11 Comment(3)
Hmm, I can't get exceptionFormat "full" to do anything. Has this been changed recently?Polygamy
Yeah, this is especially helpful for a Semaphore build where you can't access the test reports. Thanks!Transpolar
In Gradle Build Language Reference, also check TestLogging.Fissiparous
B
0

Try gradle --stacktrace test. I believe that will show the stacktraces that produced the test failures/errors.

You could also perhaps add the --debug option also for additional information.

Brough answered 24/6, 2014 at 2:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.