Can not see the real exception in gradle tests


(mrnuke) #1

I have test class A that extends some base class from external library

class A extends com.thirdparty.BaseClass {

@Test public void test () {
    System.out.println("executing test")
}

}

Base class sets up my set environment and throws exception if environment can not be properly configured

class BaseClass {

BaseClass() {
    boolean result = setupEnvironment();
    if (result == false) {
          throw new RuntimeException("Environment exception")
    }
}

}

in that case when I run test with gradle from command line, it gives me java.lang.NoClassDefFoundError error, and I have no clue that the real exception is RuntimeException.

What I want, is to see the real RuntimeException anywhere. Its really hard to investigate the issue because I dont see the real problem

I’ve tried

tasks.withType(Test) {
testLogging {
showStandartStreams = true
}
}

but it gave no result.

Gradle version is 4.1


(James Justinic) #2

The java.lang.NoClassDefFoundError is the real exception here. You’re likely not making it to the RuntimeException because you’re missing a class you need on the classpath when the test runs. It might be a class used by setupEnvironment() or even BaseClass itself that missing from the classpath. Your dependencies block would be useful to show to see to help reveal what exactly is wrong.


(mrnuke) #3

Am I right that there is no way to see the real exception? It can be extremely useful in investigation to see, for example, stacktrace, cought by setupEnvironment()


(James Justinic) #4

No. You are seeing the real exception. It’s just not the one you expect as there are additional problems.

Execution stops on the first uncaught exception. You’ll have to fix the java.lang.NoClassDefFoundError first in order to make it to the point where another exception might be thrown.

If you need help with fixing that error, you haven’t yet provided enough information to determine what exactly is wrong in your build script to cause the java.lang.NoClassDefFoundError though.


(mrnuke) #5

I’ll answer to myself. BaseClass was really in the classpath, but for some reason it can not be loaded because of exception in initialization block. In order to see nested exception
"exceptionFormat = ‘full’ "made this job