Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

异步单元测试运行走不到testLoadRepos()里面的callback #5

Closed
mistakelijc opened this issue May 19, 2017 · 1 comment
Closed

Comments

@mistakelijc
Copy link

运行RepoModelTest,测试testLoadRepos()方法,发现它会一直在await,结束不了。后来加入log后发现代码没有走到callback的onSuccess里面,所以没有触发latch.countDown()。跟进去RepoModel里面发现是callback.onSuccess(repos)调用的问题,直接调用的话后面是能够运行到callback的onSuccess里面的;但是如果用mUiHandler.post()来调用的话就执行不到run()里面的内容了,这是为什么呢?

@ChrisZou
Copy link
Owner

Handler post出来的信息不会被Robolectric立刻执行。你需要
调用一下ShadowLooper.runUiThreadTasksIncludingDelayedTasks。参考 https://stackoverflow.com/questions/18956117/robolectric-run-handler-post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants