Print testcase execution failures on stdout/err

test-tag

(Christian Stein) #1

Hej!

I want to force test execution failure stacktraces to be printed to stdout/err. All I achieved via build --info --stacktrace and the following configuration

test {
	useJUnitPlatform()

    testLogging {
        showExceptions true
        showCauses true
        showStandardStreams true
    }
}

…is :test FAILED on stdout and on stderr something like

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///.../build/reports/tests/test/index.html

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':test'.
...
Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///.../build/reports/tests/test/index.html

The suggested report contains the information I’d like to see on the console:

<testcase name="execution failure" classname="Gradle Test Executor 1" time="0.029">
    <failure message="org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 1." type="org.gradle.api.internal.tasks.testing.TestSuiteExecutionException">org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 1.
...
Caused by: org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
	at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:297)
...

(nerro) #2

Try to set exceptionFormat to “full”.
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.logging.TestLogging.html


(Christian Stein) #3

Does not help. stdout and stderr still contain the stacktrace as above. But not the one I’m interested in.


(nerro) #4

can you share minimal example of your project?


(Christian Stein) #5

Sure. Just preparing a PR with the sample project included. Will link it here.

The project I’m configuring is an integration test project with a flawed build script by design. The Gradle Test Executor 1 should finish abnormally. The expected error is produced and recorded in the build/test-results/test/TEST-Gradle#20Test#20Executor#201.xml file. See the last snippet above. I just want to get that stacktrace printed to stdout/err.

Or control the name of the test result xmlfile. Expecting it to always be named TEST-Gradle#20Test#20Executor#201.xml is meant to fail. Or is the file name stable?


(Christian Stein) #6

Found the solution. Switching to full --debug mode when building emits the expected stacktrace to stdout:

22:41:26.921 [DEBUG] [TestEventLogger] Gradle Test Executor 1 FAILED
22:41:26.921 [DEBUG] [TestEventLogger]     org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 1.
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/java.lang.reflect.Method.invoke(Method.java:564)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
22:41:26.921 [DEBUG] [TestEventLogger]         at com.sun.proxy.$Proxy2.stop(Unknown Source)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:123)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/java.lang.reflect.Method.invoke(Method.java:564)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
22:41:26.921 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
22:41:26.921 [DEBUG] [TestEventLogger]         at java.base/java.lang.Thread.run(Thread.java:844)
22:41:26.921 [DEBUG] [TestEventLogger] 
22:41:26.921 [DEBUG] [TestEventLogger]         Caused by:
22:41:26.921 [DEBUG] [TestEventLogger]         org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
22:41:26.921 [DEBUG] [TestEventLogger]             at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:297)
22:41:26.921 [DEBUG] [TestEventLogger]             at org.junit.platform.launcher.core.DefaultLauncher.<init>(DefaultLauncher.java:55)
22:41:26.921 [DEBUG] [TestEventLogger]             at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:59)
22:41:26.921 [DEBUG] [TestEventLogger]             at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:90)
22:41:26.921 [DEBUG] [TestEventLogger]             at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$100(JUnitPlatformTestClassProcessor.java:77)
22:41:26.921 [DEBUG] [TestEventLogger]             at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:73)
22:41:26.921 [DEBUG] [TestEventLogger]             at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
22:41:26.921 [DEBUG] [TestEventLogger]             ... 25 more