简体   繁体   English

获取android gradle junit测试运行的XML / HTML测试结果

[英]Getting XML / HTML test results for android gradle junit test run

I'm having a hard time finding xml / html test results after running my tests through gradle either with ./gradlew test or ./gradlew testDebug . 在使用./gradlew test./gradlew testDebug通过gradle运行我的测试后,我很难找到xml / html测试结果。 When I run either of those I wind up with an html file that shows 0 tests and no xml file at all. 当我运行其中任何一个时,我最终得到一个html文件显示0测试,根本没有xml文件。

According to the android docs XML test results should be in path_to_your_project/module_name/build/test-results/ but the test-results folder only has .bin files in it ( results.bin , etc). 根据android docs的 XML测试结果应该在path_to_your_project/module_name/build/test-results/但是test-results文件夹中只有.bin文件( results.bin等)。 I also tried searching with find app/build -type f -name "*.xml" but only found Android related XML files (manifest, merge files, etc). 我也尝试使用find app/build -type f -name "*.xml"但只找到与Android相关的XML文件(清单,合并文件等)。

Output from ./gradlew --version 输出来自./gradlew --version

------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_212 (Oracle Corporation 25.212-b03)
OS:           Linux 4.15.0-50-generic amd64

I want to get test results to publish to jenkins. 我想让测试结果发布到jenkins。 I have the same issue if I run on my local MBP as well. 如果我在我的本地MBP上运行,我也有同样的问题。 I have not modified any of the gradle test configurations but the link above seems to suggest I shouldn't need to. 我没有修改任何gradle测试配置,但上面的链接似乎表明我不应该这样做。

I also tried specifying my test directory with 我也试过用。指定我的测试目录

android {
    ...
    sourceSets {
        androidTest {
            java.srcDirs = ['src/test/java']
        }
    }
}

run following command from android studio terminal/or ubuntu machine. 从android studio terminal /或ubuntu机器运行以下命令。

gradlew tasks

see the list of options available under group test and use for respective flavor. 查看组测试下可用的选项列表,并用于各自的风格。

gradlew testDebugUnitTest

[in my app i am using this command. [在我的应用程序中我正在使用此命令。 Output is generated in 'C:\\Users\\abc\\Desktop\\MyApplication\\app\\build\\reports\\tests\\testDebugUnitTest'] 输出在'C:\\ Users \\ abc \\ Desktop \\ MyApplication \\ app \\ build \\ reports \\ tests \\ testDebugUnitTest']中生成

Turns out I was missing this from my /app/build.gradle 结果我从我的/app/build.gradle遗漏了这个

android {
  ...
  testOptions {
    unitTests.all {
      useJUnitPlatform()
    }
  }
}

This guide helped me figure that out 本指南帮助我弄明白了

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

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