簡體   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