如何在android单元测试中创建位置?
我想使用JUnit4在android单元测试中创建一个位置 与 位置loc=新位置(…) loc为空 如何创建位置 据我所知,我必须使用 测试编译“…” 但我找不到要包括的内容 你能帮忙吗?如何在android单元测试中创建位置?,android,junit,Android,Junit,我想使用JUnit4在android单元测试中创建一个位置 与 位置loc=新位置(…) loc为空 如何创建位置 据我所知,我必须使用 测试编译“…” 但我找不到要包括的内容 你能帮忙吗? 提前感谢。在您的模块build.gradle中: apply plugin: 'com.android.application' android { ... testOptions { unitTests.returnDefaultValues = true } }
提前感谢。在您的模块
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 {
...
}
应该是这样。你试过机器人电气吗?下面是一个使用纯JUnit在开发机器上进行单元测试的示例(即,没有设备测试)?这是行不通的,编译时android库大多是存根。