Some of our gradle tests are not outputting any logs with testng

Some of our test suites that we run in gradle do not output any logs that are running with testng.

This could be related to http://issues.gradle.org/browse/GRADLE-1252 however that was created quite a while ago.

Does anyone have any ideas why some tests eat all the log output and others log properly?

How exactly are you logging? How are you configuring TestNG in the build script? What happens if you run just the test whose logging isn’t shown?

We do our logging using log4j.

Ie Logger businessLogger = Logger.getLogger(“business”);

businessLogger.info(“Log message”)

we have this task defined in a common gradle file testable.gradle file:

task webAcceptanceTest(type: Test) {
 group = "Verification"
 description = 'Runs the web acceptance tests for this project.'
   dependsOn ':acme:core:webTestJar'
    systemProperties = System.properties
   useTestNG()
 options {
  listeners << 'org.uncommons.reportng.HTMLReporter'
  listeners << 'org.uncommons.reportng.JUnitXMLReporter'
  listeners << 'au.com.acme.common.util.SeleniumTestngListener'
 }
   classpath = sourceSets.test.output + sourceSets.main.output
 classpath += configurations.testWeb
}

Then we have a closure to configure it:

webAcceptanceTest {
   jvmArgs '-XX:MaxPermSize=256m'
   dependsOn ':acme:public:war:testClasses'
 classpath += project(':acme:public:war').configurations.testCompile
 classpath += project(':acme:public:war').sourceSets.test.resources
   testClassesDir = project(':acme:public:war').sourceSets.test.output.classesDir
   options {
  includeGroups 'webacceptance'
  excludeGroups 'webacceptance.broken', 'broken'
 }
}

The main problem we see is that if we run it like normal gradle webAcceptanceTests it will generally log properly. However when we use the single test syntax ie: gradle webAcceptanceTests -DwebAcceptanceTest.single=Classname it won’t log to the stdout anymore. Parts of the logs still appear in the output html files, but anything other than what caused the test failure is lost.

I’m surprised that you see any logging at all. Usually you have to do ‘webAcceptanceTest.testLogging.showStandardStreams = true’ to get std out displayed. Also, log4j needs to be configured to log to std out (which is probably the default if it can’t find a configuration file).

Ahh that was exactly the problem. It must have been working by accident before. Thanks heaps :slight_smile: