I cannot run tests with Robolectric when I try to run tests:
./gradlew test
I get the following exception:
com.Makeupalley.test.HomeRobolectricTest > initializationError FAILED java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException java.lang.NoClassDefFoundError: android/app/Activity at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) . . . Caused by: java.lang.ClassNotFoundException: android.app.Activity at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
The test fails with any statement like this: assertTrue (true).
This is my build.gradle:
buildscript { repositories { mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } } dependencies { classpath 'com.android.tools.build:gradle:0.12.+' classpath 'org.robolectric:robolectric-gradle-plugin:0.12.+' } } ... dependencies { compile('junit:junit:4.11') { exclude module: 'hamcrest-core' } compile('org.robolectric:robolectric:2.3') { exclude module: 'classworlds' exclude module: 'commons-logging' exclude module: 'httpclient' ... } }
Test file:
@Config(emulateSdk = 18) @RunWith(RobolectricTestRunner.class) public class HomeRobolectricTest { private TestActivity activity; public HomeRobolectricTest(){} @Before public void setup() { activity = Robolectric.buildActivity(TestActivity.class).create().get(); } @Test public void testInstanceActivity() throws Exception { assertTrue(true); } ... }
Can someone help me give me some recommendations?
If you need more information or the build.gradle file, I can publish it.
build.gradle file: https://gist.github.com/anonymous/d0f0bac71a0fb76f8454
thanks
UPDATE - Android section
android { compileSdkVersion 15 buildToolsVersion '19.1.0' defaultConfig { minSdkVersion 10 targetSdkVersion 15 versionCode 45 versionName "1.4.210" testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" } buildTypes { release { runProguard true proguardFile 'proguard-project.txt' } debug { runProguard false testCoverageEnabled = true } } signingConfigs { } packagingOptions { exclude 'META-INF/INDEX.LIST' exclude 'META-INF/INDEX' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE' exclude 'LICENSE.txt' exclude 'META-INF/license.txt' exclude 'META-INF/notice.txt' exclude 'META-INF/ASL2.0' } sourceSets { androidTest { setRoot('src/test') } } lintOptions { checkReleaseBuilds false abortOnError false } }
source share