如何解决android测试中的空对象
我正在使用Spock在android中进行测试。 (我也尝试在Kotlin
和Java
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 举报,一经查实,本站将立刻删除。