une*_*ewk 6 android android-testing android-espresso
我在使用espresso意图来测试使用意图启动的活动时遇到了麻烦.执行流程以下列方式工作
创建intent并启动新活动的代码如下所示:
@Override
protected void onPostExecute(String result) {
Intent intent = new Intent(context, NewActivity.class);
intent.putExtra(key, result);
context.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
这一切都在我运行应用程序时有效.至于使用espresso进行测试,测试代码如下所示:
...
@Rule
public IntentsTestRule<MainActivity> mIntentTestRule =
new IntentsTestRule<>(MainActivity.class, false);
@Test
public void testMainActivityAsyncTask() {
// Find view with button
onView(withText(R.string.button_text)).perform(click());
// Ensure correct intent setup
intended(allOf(
hasComponent(NewActivity.class.getName()),
hasExtraWithKey(key),
toPackage("com.example.espresso")));
// Ensure appropriate activity and view is launched
onView(
allOf(withId(R.id.expected_view),
withText(isEmptyOrNullString())));
// Let it go
Intents.release();
}
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,测试失败并出现这些错误(为简洁起见):
...想要匹配1个意图.实际上匹配0意图.
匹配意图:[]
记录的意图:-Intent {cmp = com.example.doingstuff/com.example.espresso.NewActivity(has extras)}处理包:[[com.example.doingstuff]],extras:[Bundle [{akey = aVal]] )
这里有几个问题:1.为什么错误消息中的cmp值前面是我的MainActivity类的包名,即"com.example.doingstuff /"可能是我的问题的一部分2.上面的错误消息是否表明它找到了一个意图,即"com.example.doingstuff/com.example.espresso.NewActivity",但它与我的预期不符?
我在没有帮助的情况下做了很多谷歌搜索.任何帮助是极大的赞赏.
| 归档时间: |
|
| 查看次数: |
635 次 |
| 最近记录: |