android测试中的空对象

问题描述

我正在使用Spock在android中进行测试。 (我也尝试在KotlinJava JUnit测试中做到这一点。)

我正在尝试创建帐户来模拟accountManager.getAccountsByType(any) >> [testAccount]中的AccountManager方法

要创建Account,我正在使用:

new Account(testUserName,testAccountType)

在调试中,它看起来像: Account object in debug

这是再现它的完整测试代码

import android.accounts.Account
import spock.lang.Specification

class Test extends Specification {
    def accountManagerMock = Spy(AccountManager)
    def testUserName = "testUserName"

    def testAccountType = "testAccountType"

    final testAccount = new Account(testUserName,testAccountType)

    def "Test"() {
        when:
        def account = new Account(testUserName,testAccountType)
        accountManagerMock.getAccountsByType(testAccountType) >> [account]

        then:
        account != null
    }
}

在调试帐户中,null为空,如所附屏幕截图所示。 我应该怎么做才能在Android测试中正确创建一个Account对象?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)