如何在Android单元测试中创建位置? [英] How can I create a Location in an android Unit-Test?

查看:64
本文介绍了如何在Android单元测试中创建位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JUnit 4在android单元测试中创建一个位置.

I want to create a Location in an android Unit-Test using JUnit 4.

与位置loc =新位置(...)loc为空.

with Location loc = new Location(...) loc is null.

如何创建位置?

据我了解,我必须使用以下命令将位置包含在build.gradle依赖项中testCompile'...'但我找不到要包含的内容.

As I understood I have to include the Location in the build.gradle dependencies using testCompile '...' but I can't find what to include.

可以帮忙吗?预先感谢.

Can you help? Thanks in advance.

推荐答案

在您模块中的 build.gradle :

apply plugin: 'com.android.application'

android {
    ...
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {

    testImplementation 'junit:junit:4.13.2'
    testImplementation "org.robolectric:robolectric:4.2.1"
    ...
}

您的测试类必须包含以下内容:

Your test class has to contain the following:

@RunWith(RobolectricTestRunner.class)
public class LocationTest {
    ...
}

应该就是这样.

这篇关于如何在Android单元测试中创建位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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