Display names of failed Scala tests

Hi,

I’m running Scala Test in Gradle project using JavaExec task, defined as:

task scalaTests(dependsOn: ['testClasses'], type: JavaExec) {
    main = 'org.scalatest.tools.Runner'
    args = ['-R', 'build/classes/test',
            '-oNCXEHLOPQMDWSFU',
            '-l', 'org.scalatest.tags.Network',
            '-l', 'net.iponweb.tags.Vagrant', '-PS1'
    ]
    classpath = sourceSets.test.runtimeClasspath
    jvmArgs = ['-XX:MaxPermSize=512m']
}

However, if there are failed tests, the exact failed test names are buried deep inside console log and difficult to find.

At the end, I see the following summary (no failed test names mentioned):

Run completed in 1 minute, 23 seconds.
Total number of tests run: 40
Suites: completed 31, aborted 0
Tests: succeeded 39, failed 1, canceled 0, ignored 2, pending 0
*** 1 TEST FAILED ***
:my-project:test FAILED

FAILURE: Build failed with an exception.

Is there any possibility to output names of failed tests?

Thanks

Ps. Could also be that this is not Gradle related, but rather ScalaTest issue. Can anyone confirm?

I’ve been thinking about researching this kind of problem. I believe this is an opportunity to write a task which “dependsOn” the “test” task. It seems reasonable to assume that there will be property and file artifacts in a standard form that should be parseable (XMLSluper, perhaps) that can print a short summary of the failed tests.

Why do you execute these tests using the JavaExec task? ScalaTest tests
can be executed using gradles’ Test task. This task is highly
configurable when it comes to logging. see
http://gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.logging.TestLoggingContainer.html
for details

Rene,

Thanks for your suggestion, but I’m afraid it left me with more questions than before :wink:

Why do you execute these tests using the JavaExec task

Gradle’s Test Task only can work with Java tests, not Scala, am I missing something?
http://gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.Test.html

ScalaTest tests can be executed using gradles’ Test task. This task is highly configurable when it comes to logging. see TestLoggingContainer - Gradle DSL Version 8.4 for details

Well, I don’t see how this applies here, since Test Task cannot run scala tests (and by scala tests I mean ScalaTest Framework)

If it’s not too much to ask, could you point me to some sample configuration of running scala tests this way?

Thanks,

We have an integration test in the gradle codebase that checks that the Test task can be used to run ScalaTest tests. have a look at https://github.com/gradle/gradle/blob/master/subprojects/scala/src/integTest/groovy/org/gradle/scala/test/ScalaTestIntegrationTest.groovy

I guess the crucial part to get it to work with the Gradle test task here is the usage of the JUnitRunner in the testcase:

@RunWith(classOf[JUnitRunner])

Wow, thanks! Somehow I missed that.

I’m not sure though if it worth the switch, since forgetting to add an annotation will cause a test to be silently ignored, causing more than just a nuisance of finding failed test. I wish we could annotate a top-level package to prevent missing tests.

Well, turns out there is another gotcha with using JUnitRunner: it won’t run if useTestNG() is used in build script.

Any chance we can run java tests with testNG and scala tests with JUnit, so JUnitRunner would be able to start scala tests?