Gradle JUnit测试报告不是XML格式。

4
我正在为一个Android Gradle项目设置CI。为了向CI报告,我需要标准的junit xml格式的报告文件。
在测试失败时,这是我得到的输出。
* What went wrong:
Execution failed for task ':Mobile Application:testDevelopmentDebugUnitTest'.
> There were failing tests. See the report at:         file://path/build/reports/tests/developmentDebug/index.html

当我在构建路径下搜索任何xml文件时,没有任何文件存在。

我正在使用Gradle的3.3版本,并且以下是一些相关的build.gradle细节:

android {
    dependencies {

        //test project dependencies
        androidTestCompile 'com.android.support:support-annotations:23.2.0'
        androidTestCompile 'com.android.support.test:runner:0.4.1'
        androidTestCompile 'com.android.support.test:rules:0.4.1'

        // Optional -- UI testing with Espresso
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
        // Required -- JUnit 4 framework
        testCompile 'junit:junit:4.12'
    }
}

不确定我缺少什么以获得一个junit格式的xml报告。


你是在尝试运行单元测试还是Espresso测试?'Application:testDevelopmentDebugUnitTest' 是用于单元测试的。对于Espresso测试,它可能是:connectedDevelopmentDebugAndroidTest(取决于你的构建变体)。 - satyajit
@ksondore,请在可行的情况下将答案标记为解决方案。 - HX_unbanned
1个回答

1

我来这里是寻找“如何从Gradle获取JUnit XML”

看起来(在Gradle 5.0中)可以使用以下方式实现;

plugins {
    id 'java'
    id 'application'
}

repositories { mavenCentral() }

test {
    reports {
        junitXml.enabled = true
    }
}

dependencies {
    testCompile 'junit:junit:4.12' // didn't work with jupiter/version5
}

...但是你的结果可能会有所不同。


1
这对我来说不起作用。在使用grade test时,添加了test {}代码后没有创建文件夹。在Win10上使用最新的稳定版Android Studio捆绑的最新Gradle版本。 - HX_unbanned
1
这个解决方案对于Android Gradle项目不起作用。在纯Kotlin模块中,使用jUnit 5是完全没问题的。 - Janusz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接