【发布时间】:2014-02-14 22:47:41
【问题描述】:
// use case 10b alternate version
// caches a read comment temporarily
public void testCacheReadComment2() throws Throwable{
runTestOnUiThread(new Runnable()
{
@Override
public void run(){
CommentBuilder commentBuilder = new commentBuilder();
Comment comment = commentBuilder.createTopTestComment();
//browse button on main screen
((Button)activity.findViewById(ca.ualberta.cs.team5geotopics.browseButton)).performClick();
//the ListView for the custom adapter
ListView listView = (ListView) activity.findViewById(ca.ualberta.cs.team5geotopics.commentList);
//the custom adapter on the physical screen
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) listView.getAdapter();
adapter.add(comment);
adapter.notifyDataSetChanged();
View view = adapter.getView(adapter.getPosition(comment), null, null);
ViewAsserts.assertOnScreen(listView, view);
//this is the button to view the Top Level comment in the list
ViewAsserts.assertOnScreen(view, (Button) view.viewTopLevelComment);
((Button)view.viewTopLevelComment).performClick();
// is there a way I can get references to the objects
// already instantiated in the test thread?
CacheController cc = activity.getCacheController();
assertTrue(cc.getHistory().contains(comment));
}
});
}
我们正在使用测试驱动的开发风格来为我们的学校项目编写代码。在这个测试中,我试图证明在用户查看适配器列表中的评论后,该评论被缓存在历史缓存中。我对某些事情有点困惑,我需要一些帮助,因为如果我知道我的测试用例中没有明显的缺陷,那就太好了。这些是我的问题:
View view = adapter.getView(adapter.getPosition(comment), null, null);
此行是否会返回与存储在数组适配器中的注释关联的视图?我的 ArrayAdapter 将遵循持有者模式,我不确定这是否是访问我需要模仿用户查看评论的按钮的正确方法。
CacheController cc = activity.getCacheController();
我有一个CacheController 对象,它在我们的主要活动中的onCreate() 方法上实例化。现在我想引用这个CacheController 来查看历史记录是否正确更新。我只是制作了一个新的CacheController 并在测试方法中模仿CacheController 的动作,但我想测试我在UIthread 上的数据会发生什么。那么,如何在 UI 线程中引用对象呢?
【问题讨论】:
标签: java android junit android-arrayadapter ui-thread