My Android gradle and robolectric unit tests were running fine until I had to write unit tests for a class that used JSONException or anything from the org.json package.
apply plugin: 'android'
apply plugin: 'com.android.application'
apply plugin: 'robolectric'
apply plugin: 'crashlytics'
apply plugin: 'jacoco' //provides code coverage metrics
dependencies {
// regular dependences
...
// unit testing
androidTestCompile fileTree(dir: 'libs/test', include: '*.jar')
androidTestCompile('com.squareup:fest-android:1.0.+') {
exclude group: 'com.android.support'
}
androidTestCompile 'com.google.dexmaker:dexmaker:1.+'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}
The exception that I am getting is the following which is weird because all the builds are fine. Any idea? Does it have something to so with my exclusions for robolectric?
java.lang.NoClassDefFoundError: org/json/JSONException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585)
at java.lang.Class.getConstructors(Class.java:1522)
at org.junit.runners.model.TestClass.<init>(TestClass.java:39)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:75)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at org.robolectric.RobolectricTestRunner.<init>(RobolectricTestRunner.java:62)
...
Any idea why I would run into this?
Aucun commentaire:
Enregistrer un commentaire