简体   繁体   English

android 连接测试的定制测试报告(浓缩咖啡)

[英]custom test report for android connected tests (espresso)

We have a JUnit test Rule for espresso tests that records test results in a json file.我们有一个用于浓缩咖啡测试的 JUnit 测试Rule ,该规则将测试结果记录在json文件中。 After test execution the json file is pulled from the device/emulator back to the pc, using adb shell pull command.执行测试后,使用adb shell pull命令将 json 文件从设备/仿真器拉回 PC。

above solution works only if we run the test using adb but not with Gradle.仅当我们使用adb而非 Gradle 运行测试时,上述解决方案才有效。 Gradle uninstalls the apk after running the connected tests, therefore the json file also gets removed from the device. Gradle 在运行连接的测试后卸载 apk,因此 json 文件也会从设备中删除。

my question: Is there a way to copy the file before it gets deleted by Gradle?我的问题:有没有办法在文件被 Gradle 删除之前复制文件?
I was wondering how other report generators tackle this issue?我想知道其他报告生成器如何解决这个问题?

Pulling most of this idea from here , but the tl;dr is that you can set up a gradle task to pull the file off of the device.这里提取大部分想法,但 tl;dr 是您可以设置 gradle 任务以将文件从设备中拉出。

Real rough idea would be:真正粗略的想法是:

def pullJsonFromEmulator = task('Pull Json From Emulator', type: Exec) {
    executable "${android.getAdbExe().toString()}"
    args 'pull', 'pathToJson', 'destinationPath'
}

tasks.withType(Test) { task -> 
    task.finalizedBy {
        pullJsonFromEmulator
    }
}

The thought process is that you define your custom task to run that will pull the Json off of the emulator and store it somewhere.思考过程是您定义要运行的自定义任务,该任务会将 Json 从模拟器中拉出并将其存储在某处。 You can then use gradle's finalizedBy functionality to apply this task after all "test" tasks.然后,您可以使用 gradle 的finalizedBy功能在所有“测试”任务之后应用此任务。 You can obviously make it more granular, say only tasks with a certain name...你显然可以让它更细化,只说具有特定名称的任务......

tasks.withType(Test) { task -> 
    if (task.name == "jsonTestTask") {
        task.finalizedBy {
            pullJsonFromEmulator
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM