2016-05-07 5 views
2

я аннотированный мой класс, как здесьAndroidJUnit4 тест не нашел

@RunWith(AndroidJUnit4.class) 
public class WorkdayProviderTest 

Futhermore, аннотированный также мой метод испытания, как этот

@Test 
public void insert_dataInsertsCorrectly() 

Наконец, настроил мой build.gradle defaultConfig и зависимостей, как этот

defaultConfig { 
    applicationId 'com.jueggs.workinghours' 
    minSdkVersion 16 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 

androidTestCompile "junit:junit:4.12" 
androidTestCompile "com.android.support:support-annotations:23.3.0" 
androidTestCompile "com.android.support.test:runner:0.4.1" 
androidTestCompile "com.android.support.test:rules:0.4.1" 
androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.1" 
androidTestCompile "com.android.support.test.espresso:espresso-contrib:2.2.1" 
androidTestCompile "org.hamcrest:hamcrest-library:1.3" 

и сконфигурировали тестовый прогон следующим образом:

enter image description here

и подмигнули говорит мне

No tests were found 

Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException' 

Как исправить эту проблему?

ответ

1

У вас может не быть что-то в ваших зависимостях от Gradle. Вы правильно заявили com.android.support.test:runner (факультативно com.android.support.test:rules)?

Пожалуйста, посмотрите на мой build.gradle файл:

apply plugin: 'com.android.application' 
apply plugin: 'android-apt' 

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:1.5.0' 
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6' 
    } 
} 

apt { 
    arguments { 
     androidManifestFile variant.outputs[0].processResources.manifestFile 
     resourcePackageName "com.piotr.testexample" 
    } 
} 

repositories { 
    mavenCentral() 
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 
} 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    useLibrary 'org.apache.http.legacy' 

    //For building with Travis CI 
    lintOptions { 
     abortOnError false 
    } 

    packagingOptions { 
     exclude 'META-INF/services/javax.annotation.processing.Processor' 
    } 

    defaultConfig { 
     applicationId "com.piotr.testexample" 
     minSdkVersion 16 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 
dependencies { 
    ext.JUNIT_VERSION = '4.12' 
    ext.AA_VERSION = '4.0.0' 
    ext.SUPPORT_VERSION = '23.3.0' 
    ext.ESPRESSO_VERSION = '2.2.2' 

    apt "org.androidannotations:androidannotations:$AA_VERSION" 
    compile "org.androidannotations:androidannotations-api:$AA_VERSION" 

    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile "junit:junit:$JUNIT_VERSION" 
    testCompile("org.robolectric:robolectric:3.0") { 
     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' 
    } 

    compile "com.android.support:appcompat-v7:$SUPPORT_VERSION" 
    compile "com.android.support:design:$SUPPORT_VERSION" 
    compile "com.android.support:cardview-v7:$SUPPORT_VERSION" 
    compile "com.android.support:recyclerview-v7:$SUPPORT_VERSION" 

    compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT' 

    compile 'com.squareup.retrofit:retrofit:1.9.0' 
    compile 'com.google.code.gson:gson:2.4' 
    compile 'com.squareup.picasso:picasso:2.5.2' 

    androidTestCompile "com.android.support:support-annotations:$SUPPORT_VERSION" 
    androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION" 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$ESPRESSO_VERSION" 
    /** 
    * AccessibilityChecks 
    * CountingIdlingResource 
    * DrawerActions 
    * DrawerMatchers 
    * PickerActions (Time and Date picker) 
    * RecyclerViewActions 
    */ 
    androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") { 
     exclude group: 'com.android.support', module: 'appcompat' 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude group: 'com.android.support', module: 'support-v7' 
     exclude group: 'com.android.support', module: 'design' 
     exclude module: 'support-annotations' 
     exclude module: 'recyclerview-v7' 
    } 

    compile "junit:junit:${JUNIT_VERSION}" 
} 

EDIT: Проблема с аннотацией, пожалуйста, выполните одно из следующих решений:

  • удалить @RunWith(AndroidJUnit4.class)
  • изменения @RunWith(AndroidJUnit4.class) с @RunWith(JUnit4.class)

Кажется, что в тестовых пакетах больше нет AndroidJUnit4.class.

+0

yes У меня есть эти зависимости, см. update – Lemao1981

+1

delete '@RunWith (AndroidJUnit4.class)' и запустить тест. Вы также можете изменить '@RunWith (AndroidJUnit4.class)' с '@RunWith (JUnit4.class)' и он должен работать. – piotrek1543

+0

не решает проблему, в обоих случаях не удается найти какой-либо тест. в версии 0.4.1 класс AndroidJUnit4 существует – Lemao1981

-1

Try именования классов и методов в этом Fashon:

  • Test_MyClass
  • test_myMethod

Я надеюсь, что это помогает.

+0

нет, не помогло – Lemao1981

+0

Прошу прощения. Я решил и решил эту проблему таким образом с помощью тестов Espresso Instrumentation. В любом случае в модульном тесте я использую Robolectric. Если вы почувствуете застревание, попробуйте! –

+0

В андроид-студии в вариантах Build Variants вы переключились с инструментальных тестов на модульные тесты? –

0

ОК, проблема не была связана с моей тестовой конфигурацией, но отсутствовал другой класс, который я удалил незадолго до этого. само приложение даже не начиналось. жаль, что имя класса не упоминалось нигде

Смежные вопросы