对test(AVD)的测试-失败:由于“ java.io.IOException”,测试运行失败 [英] Tests on test(AVD) - failed: Instrumentation run failed due to 'java.io.IOException'

查看:79
本文介绍了对test(AVD)的测试-失败:由于“ java.io.IOException”,测试运行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android模拟器上使用 Gradle 运行 Cucumber-jvm 测试时,出现此错误。

I get this error when running my Cucumber-jvm tests with Gradle on an Android emulator.

完全相同的测试可以在设备上完美运行,但是我需要在模拟器上运行它们才能在Travis CI上执行测试

The exact same tests run perfectly on a device but I need to run them on emulator to perform the tests on Travis CI

调试错误:

Executing task ':app:connectedDebugAndroidTest' (up-to-date check took 0.0 secs) due to:
  Task has not declared any outputs.
deleteDir(/home/travis/build/neoranga55/Experiment-CI/app/build/outputs/androidTest-results/connected) returned: true
deleteDir(/home/travis/build/neoranga55/Experiment-CI/app/build/outputs/code-coverage/connected) returned: true
Starting 0 tests on test(AVD) - 5.0.2
Tests on test(AVD) - 5.0.2 failed: Instrumentation run failed due to 'java.io.IOException'

com.android.builder.testing.ConnectedDevice > No tests found.[test(AVD) - 5.0.2] [31mFAILED [0m
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).
deleteDir(/home/travis/build/neoranga55/Experiment-CI/app/build/reports/androidTests/connected) returned: true
:app:connectedDebugAndroidTest FAILED
:app:connectedDebugAndroidTest (Thread[main,5,main]) completed. Took 3 mins 13.635 secs.

FAILURE: Build failed with an exception.

执行和失败的完整日志:
https://s3.amazonaws.com/archive.travis-ci.org/jobs/81209650/ log.txt

The full log of execution and fail: https://s3.amazonaws.com/archive.travis-ci.org/jobs/81209650/log.txt

这是我创建的CucumberTestCase.class,用于配置Cucumber将执行哪些测试以及使用 @CucumberOptions :

This is the CucumberTestCase.class I created to configure which tests will be executed by Cucumber and where the results will be placed using the @CucumberOptions:

import cucumber.api.CucumberOptions;

/**
 * This class configures the Cucumber test framework and Java glue code
 */
@CucumberOptions(features = "features", // Test scenarios
        glue = {"com.neoranga55.cleanguitestarchitecture.cucumber.steps"}, // Steps definitions
        format = {"pretty", // Cucumber report formats and location to store them in phone
                "html:/mnt/sdcard/cucumber-reports/html-report",
                "json:/mnt/sdcard/cucumber-reports/cucumber.json",
                "junit:/mnt/sdcard/cucumber-reports/cucumber.xml"
        },
        tags={"~@manual", "@login-scenarios"}
)
public class CucumberTestCase {
}

启动命令为:

./gradlew connectedAndroidTest -PdisablePreDex --stacktrace --info


推荐答案

问题 java.io.IOException是因为Cucumber-jvm无法写入该位置指示d在 format 下的 @CucumberOptions 中。

The problem 'java.io.IOException' is because Cucumber-jvm can't write to the location indicated in @CucumberOptions under format.

在我的情况下,这是因为该路径存在于设备上但确实存在在模拟器上不存在,这就是为什么它仅在模拟器上失败的原因。

In my case, it's because the path exists on the device but does not exist on the emulator, that's why it fails only on emulator.

解决方案是将路径更改为 html json junit 报告到在设备和仿真器中均可写的路径

The solution is to change the path to the html, json and junit reports to a path that is writable in both device and emulator.

我的初始路径( / mnt / sdcard / cucumber-reports / html-report )非常适合放置html报告并在执行完成后进行检索。在设备和仿真器中都可以使用的路径是下面的示例,但是在通过Gradle测试执行删除应用程序之后,该路径将被删除:

My initial path (/mnt/sdcard/cucumber-reports/html-report) was great for placing the html report and retrieving it after execution is finished. The path that works in both device and emulator is the example below, but this path will be deleted after application is removed by Gradle test execution:

@CucumberOptions(features = "features", // Test scenarios
        glue = {"com.neoranga55.cleanguitestarchitecture.cucumber.steps"}, // Steps definitions
        format = {"pretty", // Cucumber report formats and location to store them in phone
                "html:/data/data/com.neoranga55.cleanguitestarchitecture/cucumber-reports/html-report",
                "json:/data/data/com.neoranga55.cleanguitestarchitecture/cucumber-reports/cucumber.json",
                "junit:/data/data/com.neoranga55.cleanguitestarchitecture/cucumber-reports/cucumber.xml"
        },
        tags={"~@manual", "@login-scenarios"}
)

这篇关于对test(AVD)的测试-失败:由于“ java.io.IOException”,测试运行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆