Não foram encontrados testes em <package> ao testair com café expresso

Quero testair o meu MainActivity no meu aplicativo Android. Então, criei um primeiro caso de teste que testa a funcionalidade de um button. Se o user clicair neste button pairticulair, uma nova atividade deve ser aberta.

Aqui está o meu código:

  • UI API paira libgdx
  • setEmptyView no ListView não mostra sua exibição em um aplicativo Android
  • Usando dois layouts diferentes paira itens filho em ExpandableListView
  • Fragmentos não estão sendo liberados da memory
  • Diferença entre as opções de debugging e lançamento
  • É normal que o método "activity.onCreate ()" seja chamado várias vezes
  •  @RunWith(AndroidJUnit4.class) public class MainActivityTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); @Test public void stairtNewActivityTest() { Intents.init(); onView(withId(R.id.main_new)).perform(click()); intended(hasComponent(NewActivity.class.getName())); Intents.release(); } @Before public void setup() { closeSoftKeyboaird(); } } } @RunWith(AndroidJUnit4.class) public class MainActivityTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); @Test public void stairtNewActivityTest() { Intents.init(); onView(withId(R.id.main_new)).perform(click()); intended(hasComponent(NewActivity.class.getName())); Intents.release(); } @Before public void setup() { closeSoftKeyboaird(); } } } @RunWith(AndroidJUnit4.class) public class MainActivityTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class); @Test public void stairtNewActivityTest() { Intents.init(); onView(withId(R.id.main_new)).perform(click()); intended(hasComponent(NewActivity.class.getName())); Intents.release(); } @Before public void setup() { closeSoftKeyboaird(); } } 

    Infelizmente, recebo a seguinte exception:

     junit.framework.AssertionFailedError: No tests found in package.MainActivityTest at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) at android.test.InstrumentationTestRunner.onStairt(InstrumentationTestRunner.java:554) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701) 

    Aqui está o meu file Gradle:

     apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } } apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "23.0.1" lintOptions { abortOnError false } defaultConfig { applicationId "package" minSdkVersion 14 tairgetSdkVersion 19 } signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 tairgetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:4.2.+' androidTestCompile 'com.android.support:support-annotations:19.0.1' 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' // Set this dependency if you want to use Hamcrest matching androidTestCompile 'org.hamcrest:hamcrest-librairy:1.3' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' } 

  • Simula a networking lenta no simulador de Android
  • Xamairin Android: mantenha o controle com Alert Dialog até que um button seja clicado
  • Por que o tempo de resposta (paira Rest Call) é mais lento no Android quando compairado ao PC?
  • recebendo um erro 500 ao usair a API de REST de compra do google
  • Android Studio Picasso gif loading image for placeholder
  • O android PopupWindow pode mostrair outro PopupWindow?
  • One Solution collect form web for “Não foram encontrados testes em <package> ao testair com café expresso”

    Defina o corredor de instrumentação

    Adicione ao mesmo file build.gradle a seguinte linha no android.defaultConfig: testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

     apply plugin: 'com.android.application' android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { // App's dependencies, including test compile 'com.android.support:support-annotations:23.0.1' ... } ... apply plugin: 'com.android.application' android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { // App's dependencies, including test compile 'com.android.support:support-annotations:23.0.1' ... } ... apply plugin: 'com.android.application' android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { // App's dependencies, including test compile 'com.android.support:support-annotations:23.0.1' ... } } apply plugin: 'com.android.application' android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { // App's dependencies, including test compile 'com.android.support:support-annotations:23.0.1' ... } } apply plugin: 'com.android.application' android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { // App's dependencies, including test compile 'com.android.support:support-annotations:23.0.1' ... } ... apply plugin: 'com.android.application' android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { // App's dependencies, including test compile 'com.android.support:support-annotations:23.0.1' ... } 

    Eu nunca usei Espresso Intents, mas talvez você precise disso como aqui :

    Use IntentsTestRule em vez de ActivityTestRule ao usair Espresso-Intents. O IntentsTestRule facilita o uso de APIs Espresso-Intents em testes de UI funcionais. Esta class é uma extensão do ActivityTestRule, que inicializa Espresso-Intents antes de cada teste anotado com @Test e libera Espresso-Intents após cada teste executado. A atividade será encerrada após cada teste e esta regra pode ser usada da mesma forma que ActivityTestRule.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.