Reputation: 11
I have an Android project in which I have a few activities as well as some regular java code, all of which I would like to be able to test using Junit. I have created an Android Junit project alongside my regular android project and included Junit 4 libraries so that I can run both android junit tests and regular junit tests.
Everything was working fine, i.e. Junit tests were running and passing, until I tried to add logging into my main project using SLF4J for Android. Now whenever I try to run a Junit test I get an error:
java.lang.NoClassDefFoundError: android/util/Log
...
Caused by: java.lang.ClassNotFoundException: android.util.Log
Does anyone have any ideas as to why this error is occurring? If there is a better way to set up my project to make both Junit and Android Junit testing possible, I'm all ears!
Upvotes: 1
Views: 977
Reputation: 69396
If you are running tests as JUnit on your host's JVM you will not be able to access Android classes like android.util.Log
.
android.jar
provides only stubs.
Upvotes: 3