由于'java.io.FileNotFoundException',检测运行失败

2022-09-02 04:50:12

我正在尝试在 Travis CI 上运行我的检测测试。当构建在Travis上运行时,我收到此错误。但是,我在本地运行测试时没有任何问题。我是Android / Java开发的新手,所以我甚至不确定从哪里开始寻找。

...

: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

...

以下是我希望运行的测试之一:

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...
    }
}

我:.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

更新:以下是一些可能与我的相关内容: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'
 }

答案 1

我也是Android的新手,但我会尽力帮助你。

您可以按照以下答案进行操作:

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

它链接到:

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

基本上,这可能是问题所在:

您可能使用不正确。compile 'com.google.dagger:dagger-compiler:2.0.2'

正确的公寓'com.google.dagger:dagger-compiler:2.0.2'

并检查此链接与您的问题相同

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


答案 2

有 2 个问题:

问题#1:

com.android.builder.testing.ConnectedDevice > 未找到测试。[测试(AVD) - 6.0]失败

这在你的例子中已经在这里描述过了。这通常意味着您的测试类不是测试运行程序期望的形式(例如,不要从 TestCase 继承或缺少@Test注释)。

为此,您可以运行

gradlew :MyappAndroid:connectedMyappDebugAndroidTest

(其中 是模块的目录名称),这将仅运行 您的 测试。MyappAndroidMyappAndroidMyappAndroid

资源链接:

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

问题#2:

对于缺少某些依赖项(如匕首),则会出现此问题。

正如artem-zinnatullin在帖子中所述

问题是您将匕首编译器编译到项目中。我不想调查为什么它会在Android 5 +上的检测测试中产生问题,但无论如何,只是不要将其编译为apk。

可能测试运行器在内部使用Dagger 2,你通过编译自己的版本来打破它,可能他们甚至使用Dagger 1,包名称是相同的。

您可以使用APT Gradle插件 https://bitbucket.org/hvisser/android-apt 编译期间运行匕首编译器,但不要将其编译到应用程序。

这是带有仪器测试和Dagger 2的#qualitymatters应用程序,一切都可以正常工作,因此您可以查看并了解如何烘焙类似的东西。

对于 Gradle 用户,请使用 https://github.com/tbroyer/gradle-apt-plugin

对于 Maven 用户,请使用 。<optional>true</optional>

匕首文档详细信息在这里:安装,等级详细信息

资源链接:

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


推荐