21

I'm trying to get my instrumentation tests running on Travis CI. I'm getting this error when the build runs on Travis. However, I don't have any problems running the tests locally. I'm new to Android/Java development so I'm not even sure where to start looking.

...

:MyappAndroid:packageMyappDebugAndroidTest
:MyappAndroid:assembleMyappDebugAndroidTest
:MyappAndroid:connectedMyappDebugAndroidTest
Tests on test(AVD) - 6.0 failed: Instrumentation run failed due to 'java.io.FileNotFoundException'

com.android.builder.testing.ConnectedDevice > No tests found.[test(AVD) - 6.0] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
:MyappAndroid:connectedMyappDebugAndroidTest FAILED

...

Here is one of my tests that I expect to run:

package core.ui.dialogs;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class DialogActivityTest {
    @Rule
    public ActivityTestRule<DialogActivity> mActivityRule = new ActivityTestRule<>(DialogActivity.class);

    @Test
    public void testSomething() {
        // etc...
    }
}

My .travis.yml:

language: android
jdk: oraclejdk7
sudo: false
env:
  global:
    - ANDROID_API_LEVEL=23
    - BUILD_TOOLS_VERSION=23.0.3
    - ANDROID_ABI=armeabi-v7a
    - ADB_INSTALL_TIMEOUT=8
android:
  components:
    - tools
    - build-tools-$BUILD_TOOLS_VERSION
    - android-$ANDROID_API_LEVEL
    - add-on
    - extra
before_script:
  - echo no | android create avd --force -n test -t android-$ANDROID_API_LEVEL --abi $ANDROID_ABI
  - emulator -avd test -no-skin -no-audio -no-window &
  - android-wait-for-emulator
  - adb shell input keyevent 82 &
script: ./gradlew assembleMyappDebug connectedMyappDebugAndroidTest -PdisablePreDex

Update: Here are a few things that may be relevant in my build.gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 23

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}
// ...
dependencies {
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.dagger:dagger:1.2.2'
    provided 'com.squareup.dagger:dagger-compiler:1.2.2'
    // ...
    androidTestCompile 'com.squareup:javawriter:2.5.0'
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
        exclude group: 'javax.inject'
    }
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
 }
Andrew
  • 227,796
  • 193
  • 515
  • 708
  • I am not familiar with Travis CI but it looks like it needs a plugin or library for executing the tests – Dan Hunex Aug 12 '16 at 21:11
  • First of all start from validating what the error message says: Find all your test classes and see whether they inherit from `TestCase` or if they dont check if the `@Test` annotation is in place – George Daramouskas Aug 12 '16 at 21:16
  • What kind of plugin/library? – Andrew Aug 12 '16 at 21:16
  • @GeorgeD I've added a code sample of my test – Andrew Aug 12 '16 at 21:20
  • I'm fixing things as I go, including upgrading plugins/libraries as I find issues. I'm not sure if the current configurations are correct. Where should I look next? – Andrew Aug 12 '16 at 21:41
  • Can you post your travis.yml file? – michaelcarrano Aug 12 '16 at 23:00
  • @michaelcarrano I have added my .travis.yml file – Andrew Aug 12 '16 at 23:54
  • @Andrew are you using dagger compiler? – Atif Farrukh Aug 15 '16 at 05:34
  • @AtifFarrukh yes, an older version I think – Andrew Aug 15 '16 at 05:48
  • I was getting "ClassNotFoundException" when i was getting dagger like this `compile "com.google.dagger:dagger-compiler:$dagger_version"`. I am not sure if it will help instead of `compile` try `apt` or `provide`. – Atif Farrukh Aug 15 '16 at 05:52
  • I have added an example of my build.gradle – Andrew Aug 15 '16 at 14:29
  • `com.android.builder.testing.ConnectedDevice > No tests found.[test(AVD) - 6.0] FAILED No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).` – xdevs23 Aug 15 '16 at 14:40
  • @xdevs23 Yes, I already read that. Doesn't my test already meet those requirements? – Andrew Aug 15 '16 at 16:19
  • @xdevs23 Ugh...I think you might have found my issue all along. I failed to commit the changes to this test file to match the example that I provided above. My actual test was using an old syntax. – Andrew Aug 15 '16 at 18:33
  • See, the message told you everything. – xdevs23 Aug 15 '16 at 18:53
  • @xdevs23 Ah, never mind. Unfortunately, I still have the same error. – Andrew Aug 15 '16 at 21:04
  • @Andrew Please see it. may be it helpful http://stackoverflow.com/questions/32678329/tests-on-testavd-failed-instrumentation-run-failed-due-to-java-io-ioexcept.... Please Ignore if nothing useful for your question... – Arjun saini Aug 19 '16 at 04:53

3 Answers3

2

I'm also new to android, but I`ll try to help you.

You can follow this answer:

https://groups.google.com/d/msg/adt-dev/QW5SuzQizNk/mWdaEuuCCQAJ

which links to:

https://github.com/google/dagger/issues/271

Basically this maybe the problem:

You might of used compile 'com.google.dagger:dagger-compiler:2.0.2' incorrectly.

The correct apt 'com.google.dagger:dagger-compiler:2.0.2'

and also check this link same as your issue

https://googleweblight.com/?lite_url=https://github.com/Shippable/support/issues/1453&ei=a6rzQlWF&lc=en-IN&s=1&m=140&host=www.google.co.in&ts=1471246688&sig=AKOVD67-05kCThujPFkmuySpywKlKpVG-g

Community
  • 1
  • 1
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81
1

There are 2 issues:

Issue#1:

com.android.builder.testing.ConnectedDevice > No tests found.[test(AVD) - 6.0] FAILED

This is already described here in your case. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

For this you can run

gradlew :MyappAndroid:connectedMyappDebugAndroidTest

(where MyappAndroid is the directory name of the MyappAndroid module), which will only run your MyappAndroid's tests.

Resource Link:

https://stackoverflow.com/a/29717892/2293534

Issue#2:

This problem occurs for some dependency missing like dagger.

As artem-zinnatullin stated in the post

The problem is that you compile dagger-compiler to the project. I don't want to investigate why it creates problems with instrumentation tests on Android 5+ but anyway, just do not compile it to the apk.

// probably test runner uses Dagger 2 internally and you break it via compiling own version, probably they even use Dagger 1, package names are same.

You can use APT Gradle Plugin https://bitbucket.org/hvisser/android-apt to run dagger-compiler during the compilation but do not compile it to the app.

Here is the #qualitymatters app with instrumentation tests and Dagger 2, everything works without problems, so you can take a look and see how to bake something similar.

For Gradle users, use https://github.com/tbroyer/gradle-apt-plugin.

For Maven users, use <optional>true</optional>.

Dagger documentation details are here: installation, gradle details

Resource Link:

https://stackoverflow.com/a/34332482/2293534

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
0

I had the same error but different testOptions and my project uses Dagger:

testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR' <---- remove this!
}

When I removed the execution line I stopped getting the error. Different bug but thought I'd share in case it can help anyone else!

alisonthemonster
  • 1,095
  • 1
  • 11
  • 28