测试测试(AVD) - 失败:由于'java.io.IOException'导致测试运行失败

时间:2015-09-20 10:32:05

标签: android cucumber-jvm

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

完全相同的测试在设备上运行完美,但我需要在模拟器上运行它们以对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

这是我创建的CucumberTestCase.class,用于配置Cucumber将执行哪些测试以及使用 @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

1 个答案:

答案 0 :(得分:3)

问题'java.io.IOException'是因为Cucumber-jvm无法写入格式 @CucumberOptions 中指示的位置。

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

解决方案是将 html json junit 报告的路径更改为可写路径

我的初始路径( / mnt / sdcard / cucumber-reports / html-report )非常适合放置html报告并在执行完成后检索它。在设备和模拟器中都有效的路径如下所示,但在Gradle测试执行删除应用程序后,将删除此路径:

@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"}
)