Android Studio 3.0 gradle 3.0.0-beta2是否突破了Kotlin单元测试的覆盖范围? [英] Android Studio 3.0 gradle 3.0.0-beta2, breaks Kotlin Unit Test Coverage?

查看:114
本文介绍了Android Studio 3.0 gradle 3.0.0-beta2是否突破了Kotlin单元测试的覆盖范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Kotlin类,如下所示

I have a simple Kotlin classes, as below

class MyClass {
    fun justSayHello(yes: Boolean): String {
        if (yes) {
            return "Hello"
        } else {
            return "Sorry"
        }
    }
}

我有测试(这里用Java编写,也可以在Kotlin中进行)

I have my test (written in Java here, could be in Kotlin, also)

public class MyClassTest {
    private MyClass myClass = new MyClass();

    @Test
    public void testFirst() {
        myClass.justSayHello(true);
    }

    @Test
    public void testSecond() {
        myClass.justSayHello(false);
    }
}

当我使用classpath 'com.android.tools.build:gradle:3.0.0-beta2'在Android Studio 3.0 Beta-2中对Coverage进行测试时,没有报告覆盖率.

When I run a test with Coverage in Android Studio 3.0 Beta-2 using classpath 'com.android.tools.build:gradle:3.0.0-beta2', no coverage is reported for it.

但是当我使用classpath 'com.android.tools.build:gradle:2.3.3'进行测试时,报告了100%的覆盖率.

But when I run the test using classpath 'com.android.tools.build:gradle:2.3.3', 100% coverage reported.

当我将源代码更改为Java时:

When I change my source code to Java:

public class MyClass {
    public String justSayHello(boolean yes) {
        if (yes) {
            return "Hello";
        } else {
            return "Sorry";
        }
    }
}

两个gradle构建工具都可以正常工作

It works fine for both gradle build tools

在我看来,'com.android.tools.build:gradle:3.0.0-beta2'对于Kotlin的测试覆盖率度量很差.

It seems to me that 'com.android.tools.build:gradle:3.0.0-beta2' has the broken test coverage measurement for Kotlin.

我错过了什么吗?我可以在Kotlin获得测试解决方案吗?

Did I miss anything? Is there a workaround for me to get the test coverage in Kotlin?

推荐答案

如果有人仍在寻找解决方案,可以添加gradle任务将案例从tmp目录复制到coverage输出所查找的目录中解决此问题的方法.

In case anyone is still looking for a solution, adding in a gradle task to copy the cases from the tmp directory into the directory that the coverage output looks in helps with this issue as a workaround.

例如,将copyTestClasses添加到模块gradle文件中

For example add copyTestClasses to your module gradle file

task copyTestClasses(type: Copy) {
    from "build/tmp/kotlin-classes/debug"
    into "build/intermediates/classes/debug"
}

然后设置默认值以在运行测试之前运行gradle任务

And then setting up your defaults to run the gradle task before running the tests

在尝试使用gradle指向它们之前,可以手动找到项目中的两个目录,以确保您指向的位置正确(风味会更改您需要指向的目录)

It can help to find both of the directories in your project manually before trying to point to them using gradle, to make sure that you're pointing to the right place (flavours will change the directories that you need to point to)

这篇关于Android Studio 3.0 gradle 3.0.0-beta2是否突破了Kotlin单元测试的覆盖范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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