How to make TestNG print detail message about the failure

Viewed 409

My testNG failed with simple message:

[TestNG] [ERROR]
Cannot instantiate class com.xyz.AbcTest

However I don't know why it cannot instantiate the class. How can I make TestNG print out the detail information or the error stack in this case?

2 Answers

Assuming you are using the maven-surefire-plugin for execution of the TestNG test . For enabling the full stack trace on the console we need to set trimStackTrace to false

trimStackTrace : Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace. Default value is: true. User property is: trimStackTrace.*

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
            <trimStackTrace>false</trimStackTrace>
            <suiteXmlFiles>
                <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>
        </configuration>

    </plugin>

With above setting for maven project you should be able to see full stack trace.

Below are remote console outputs with trimStackTrace :

For : trimStackTrace:true

[ERROR] com.interfaces.TestClass.testing[Edge, org.testng.TestRunner@28467629](2)  Time elapsed: 0.008 s  <<< FAILURE!
java.lang.NullPointerException
        at com.interfaces.TestClass.testing(TestClass.java:32)

[ERROR] com.interfaces.TestClass.testing[Chrome, org.testng.TestRunner@28467629](2)  Time elapsed: 0.009 s  <<< FAILURE!
java.lang.NullPointerException
        at com.interfaces.TestClass.testing(TestClass.java:32)

[INFO]

---------------------------------------------------

For trimStackTrace :false

[ERROR] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.477 s <<< FAILURE! - in TestSuite
[ERROR] com.interfaces.TestClass.testing[Edge, org.testng.TestRunner@2dc7f489](2)  Time elapsed: 0.014 s  <<< FAILURE!
java.lang.NullPointerException
        at com.interfaces.TestClass.testing(TestClass.java:32)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
        at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
        at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
        at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:77)
        at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:15)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Related