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,

ant2009
  • 27,094
  • 154
  • 411
  • 609

2 Answers2

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.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Hmm, I can't get `exceptionFormat "full"` to do anything. Has this been changed recently? –  Nov 18 '14 at 12:15
  • Yeah, this is especially helpful for a Semaphore build where you can't access the test reports. Thanks! – Todd W Crone Apr 08 '15 at 14:44
  • In _Gradle Build Language Reference_, also check [TestLogging](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.logging.TestLogging.html). – José Andias Mar 06 '18 at 18:45
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.

khampson
  • 14,700
  • 4
  • 41
  • 43