在意图中使用 Robotium

编程入门 行业动态 更新时间:2024-10-24 02:02:19
本文介绍了在意图中使用 Robotium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含多个列表视图活动的应用程序,第一个列表视图中的选择决定了第二个列表视图的内容,第二个列表视图确定了第三个列表视图的内容,依此类推.

I have an application with several activities with list views, the selection from the first list view determines the content of the second list view, and the second list view determines the contents of the third, etc.

我想测试第三个列表视图,但由于它需要一个意图,因此该列表不返回任何内容.为了解决这个问题,我可以手动将意图添加到测试中,这确实意味着它有效

I want to test the third list view, but as it requires an intent the list returns nothing. To remedy this I can manually add the intent to the test which does mean it works

public InspectionListActivityTest() { super(InspectionListActivity.class); Intent i = new Intent(); i.putExtra("guid", "abcbbf2b-5e14-4cb1-af1b-e3084b45d4cf"); setActivityIntent(i); }

正如您从代码中看到的,它使用 guid 来确定我想要避免的列表 - 我在测试时清除了很多数据库,因此我必须一直更改此字段.

As you can see from the code, it uses guids to determine the list which is what I want to avoid - I clear the database a lot while I'm testing so I have to change this field all of the time.

理想情况下,我想使用 ContentResolver 从另一个表中获取第一个 guid,这意味着我可以始终在测试中提取信息,即

Ideally I want to use a ContentResolver to get the first guid from another table which would then mean I would be able to always pull back information in my tests, ie

public InspectionListActivityTest() { super(InspectionListActivity.class); ContentResolver cr = getActivity().getContentResolver(); Cursor cursor = cr.query(Locations.CONTENT_URI, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { String guid = cursor.getString(cursor.getColumnIndex(Locations.GUID)); Intent i = new Intent(); i.putExtra(IntentFilters.LOCATION.getIntent(), guid); setActivityIntent(i); } } }

但是,我在 getActivity() 方法上得到了 nullpointerexception,而且我似乎无法将此 setActivityIntent 放在其他任何地方.

However, I get a nullpointerexception on the getActivity() method, and I don't seem to be able to put this setActivityIntent anywhere else.

推荐答案

可以做到,但是有点乱.基本上从我想要的数据库中获取了 guid,为原始测试类创建了一个新意图,将 guid 附加到意图,然后启动了意图.

It can be done, but it's a bit messy. Basically got the guid from the database that I wanted, created a new intent to the original test class, attached the guid to the intent and then started the intent.

public void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); activity = getActivity(); UsefulFunctions.insertDummyData(getActivity()); ContentResolver cr = getActivity().getContentResolver(); Cursor cursor = cr.query(Locations.CONTENT_URI, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { guid = cursor.getString(cursor.getColumnIndex(Locations.GUID)); } } solo.goBack(); Intent i = new Intent(activity.getApplicationContext(), InspectionListActivity.class); i.putExtra(IntentFilters.LOCATION.getIntent(), guid); setActivityIntent(i); activity.startActivity(i); }

在某种程度上,从我的第一个列表开始,然后让 Robotium 在列表中单击"一直到我想要的屏幕更容易,即

In a way, it was just easier to start on my first list and then get Robotium to 'click' in the list all the way to the screen that I wanted, i.e.

solo.clickInList(0); // Locations solo.clickInList(0); ListView ls = solo.getCurrentListViews().get(0); solo.waitForActivity("InspectionListActivity");

更多推荐

在意图中使用 Robotium

本文发布于:2023-11-28 07:42:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   在意   Robotium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!