robolectric test case failure investigation

One of my colleagues said unit testing failed in jenkins, so i volunteered to take a look. It was supposed to be a 10 mins work, i guessed somebody changed the tool method, but didn’t update the test case.

So i added breakpoint in one of the failed test cases then ready to go. The weird thing was, the process didn’t go that far, it fails at some point before the breakpoint, and all of the test cases failed. So i checked the log, there were many errors :

java.util.ServiceConfigurationError: org.robolectric.internal.ShadowProvider: Provider org.robolectric.shadows.multidex.Shadows not a subtype

I had no clue about this, so i tried last version of our app, it seemed all good. Then i checked the gradlew file to find out what changed in the build, and then find out we imported a new library. So the error was caused by that library, i was told not allowed to remove that library. Ok, continue to google another solution, somebody mentioned upgraded robolectric may solve this. I upgrade it, and get a different error:

java.lang.VerifyError: Expecting a stackmap frame at branch target 106

for this error, i can get a lot of information from internet, the main reason is the third library proguard setting, it should proguarded as a library, not an app, this page is very detailed:

so i added following snippet in the build.gradle, everything is back to normal. I guess the last thing is to notify the third library to change they proguard setting.

testOptions {
 unitTests {
 all {
 jvmArgs '-noverify'
 }
 }
 }

What a typical day doing Google-oriented programming!

Like what you read? Give Xingchao Song a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.