繁体   English   中英

如何在 android 单元测试中创建位置?

[英]How can I create a Location in an android Unit-Test?

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

使用 Location loc = new Location(...) loc 为空。

如何创建位置?

据我所知,我必须使用 testCompile '...' 在 build.gradle 依赖项中包含 Location,但我找不到要包含的内容。

你能帮忙吗? 提前致谢。

在您的模块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"
    ...
}

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

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

应该就是这样。

暂无
暂无

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

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