2014-05-19 11 views
5

To jest mój Gradle plik:Android Studio z Robolectric: mój sprawdzian klasa nie zostanie znaleziony

apply plugin: 'android' 
apply plugin: 'android-test' 

android { 
// Check on it to know witch Android API level is necessary: 
// http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels 
compileSdkVersion 19 
buildToolsVersion '19.0.1' 

defaultConfig { 
    minSdkVersion 14 
    targetSdkVersion 19 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 
} 
buildTypes { 
    release { 
     runProguard false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
    } 
} 
sourceSets { 
    androidTest { 
     setRoot('src/test') 
    } 
} 
// Patch: http://stackoverflow.com/questions/20673888/duplicate-files-copied-android-studio-0-4-0 
packagingOptions { 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/license.txt' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/notice.txt' 
    exclude 'META-INF/ASL2.0' 
} 
} 

androidTest { 
include '**/*Test.class' 
exclude '**/espresso/**/*.class' 
} 

dependencies { 

// Android SDK Extra librairies 
compile 'com.android.support:support-v4:19.0.+' 
compile 'com.android.support:appcompat-v7:19.0.+' 
compile fileTree(dir: 'libs', include: ['*.jar']) 

// Android testing 
// http://robolectric.org/ 
androidTestCompile 'junit:junit:4.+' 
androidTestCompile 'org.robolectric:robolectric:2.+' 
androidTestCompile 'com.squareup:fest-android:1.0.+' 
// had to deploy to sonatype to get AAR to work 
//compile 'com.novoda:actionbarsherlock:4.3.2-SNAPSHOT' 

}

To mój korzeń Gradle plik:

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
repositories { 
    maven { url "http://dl.bintray.com/populov/maven" } 
    mavenCentral() 
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 
} 
dependencies { 
    classpath 'com.android.tools.build:gradle:0.9.+' 
    //classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+' 
    //classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT' 
    classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+' 
} 
} 

allprojects { 
repositories { 
    maven { url "http://dl.bintray.com/populov/maven" } 
    mavenCentral() 
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } 
} 
} 

wystarczy napisać prosty klasa do przetestowania w celu sprawdzenia poprawności testu infrastruktury, ale mam ten błąd:

Class not found: "com.example.myapp.activity.BaseActivityTest"

Moja klasa jest badanie:

package com.example.myapp.activity; 

import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.robolectric.RobolectricTestRunner; 

import static org.junit.Assert.*; 

@RunWith(RobolectricTestRunner.class) 
public class BaseActivityTest { 
@Test 
public void testTrueIsTrue() throws Exception { 
    assertEquals(true, true); 
} 
} 

folder Moje achitecture jest:

  • MojaApl

    • src

      • główny

        • java
          • com.example.moja_aplikacja ...
      • Test

        • java
          • com.example.moja_aplikacja ...

Nie rozumiem, dlaczego pojawia się ten błąd.

Dziękuję wam!

+0

Hej Anthony Mam działającą konfigurację dla Androida Studio 0.4.6, ale wiem, że późniejsza wersja Androida Studio spowodowała problemy - zadałem [to pytanie] (http://stackoverflow.com/q/23116409/1348379) reakcja ogłuszającego milczenia! Jaką wersję AS uruchamiasz? – OceanLife

+0

Hej OceanLife! To jest ostatnia wersja 0.5.5. Dzięki! – anthony

Odpowiedz

0

Ok chłopaki, znalazłem rozwiązanie:

To mój Gradle plik:

apply plugin: 'android' 
apply plugin: 'robolectric' 

android { 
// Check on it to know witch Android API level is necessary: 
// http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels 
compileSdkVersion 19 
buildToolsVersion '19.0.1' 

defaultConfig { 
    minSdkVersion 14 
    targetSdkVersion 19 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 
} 
buildTypes { 
    release { 
     runProguard false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
    } 
} 
sourceSets { 
    androidTest { 
     setRoot('src/test') 
    } 
} 
} 

// prevent the "superClassName is empty" error for classes not annotated as tests 
tasks.withType(Test) { 
scanForTestClasses = false 
include "**/*Test.class" // whatever Ant pattern matches your test class files 
} 

dependencies { 

// Android SDK Extra librairies 
compile 'com.android.support:support-v4:19.0.+' 
compile 'com.android.support:appcompat-v7:19.0.+' 
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) 

// Android testing 
//androidTestCompile configurations.androidTestCompile.dependencies 
// http://robolectric.org/ 
androidTestCompile 'org.robolectric:robolectric:2.+' 
androidTestCompile 'junit:junit:4.+' 
} 

I zmodyfikowane mój VM argumentu (wydanie Configuration) jak tego postu: http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments

+0

Nigdy nie będę miksować androida + robolektryka w tym samym module. To wyklucza espresso (nadal działa bardzo wolno), w AS dodam do domyślnego zadania junit dodatkowy zewnętrzny krok kompilacji, aby AS generował pliki klas. Opisy szczegółów można znaleźć tutaj https: // github.com/nenick/android-gradle-template/wiki/Tests-in-Android-Studio --- IntellJ – nenick

Powiązane problemy