Monday, June 29, 2015

Get detailed stack traces of failed tests in Gradle

When a test failed in Gradle,

you will get the following stack trace:

com.izeye.test.SomeTests > test FAILED
    java.lang.IllegalStateException                                                    
        Caused by: org.springframework.beans.factory.BeanCreationException              
            Caused by: java.lang.NoClassDefFoundError                                  
                Caused by: java.lang.ClassNotFoundException

But it's sometimes not useful.

When you want to get a detailed stack trace,

add the following configuration:

    test {
        testLogging {
            exceptionFormat = 'full'
        }
    }

Now you will get the following output:

com.izeye.test.SomeTests > test FAILED  
    java.lang.IllegalStateException: Failed to load ApplicationContext                  
                                                                                       
        Caused by:                                                                      
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/izeye/test/config/PersistenceConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefF
oundError: org/w3c/dom/ElementTraversal
                                                                                       
            Caused by:                                                                  
            java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal                
                                                                                       
                Caused by:                                                              
                java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal      

Now you can see that the culprit was `org.w3c.dom.ElementTraversal `.

Reference:
http://java.dzone.com/articles/gradle-goodness-show-more

No comments:

Post a Comment