I'm required to use Gradle for my Java project.
I'm running some unit tests with ./gradlew test
, but the exception stack trace is witten on a web page which I need to load in a browser.
Why such complication?
Is there a way of getting it on the terminal instead, as I Maven does?
If it seems like your app has crashed, the first thing you will want to do is examine the stack trace that is associated with this crash. These are logged to a facility known as Logcat, on your device or emulator. You can view those logs using the Logcat tool in Android Studio.
Gradle does not redirect its logs in a separate file in Android Studio. Therefore if you want to view them in a file, you need to build gradle using a command in the terminal and redirect gradle input to a file. This command will redirect all standard output and error messages from gradle build to a file called myLogs.
According to this page the following will do:
test {
testLogging {
exceptionFormat = 'full'
}
}
This is actually working. It's not really showing the whole exception trace, but (even better?) it shows the relevant part of it (that is, the part associated to the code written in the unittest).
For gradle (kotlin dsl) you could do this:
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
tasks {
test {
testLogging {
events("passed", "skipped", "failed")
showStackTraces = true
exceptionFormat = TestExceptionFormat.FULL
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With