android - Null object in android test
问题描述
I'm working on a test in android using Spock. (I've tried also to do this in Kotlin
and Java
JUnit
tests.)
I'm trying to create Account to mock accountManager.getAccountsByType(any) >> [testAccount]
method in AccountManager
.
To create Account
I'm using just:
new Account(testUserName, testAccountType)
In debug it looks like : Account object in debug
This is whole test code needed to reproduce it:
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
}
}
In debug account is null like on attached screenshot. What should I do to correctly create an Account object in the Android test?
解决方案
推荐阅读
- git - 当我选中“阻止命令行推送”复选框时,为什么我不能推送?
- azure - 将域的子文件夹映射到 azure app servive
- javascript - 如何使用 lodash 在 javascript 中实现多级排序?
- android - 如何在加载应用程序时存储未来数据以供进一步使用?# 颤动
- assembly - 如何堆叠(推送)xPSR?
- javascript - js中的定时动作(每秒帧数)
- bash - 将文件作为输入并在其上运行 awk 命令
- go - 如何在go中保存和加载接口结构
- python - 使用 MetPy 生成 Countour 图的问题
- c++ - 我将如何添加或乘以极大的数字,例如 20 位数字 x 5 位数字......?