使用 Robolectric 使用 Fragment 测试活动 [英] Testing Activity with a Fragment with Robolectric

查看:56
本文介绍了使用 Robolectric 使用 Fragment 测试活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查我在测试中创建的 Activity 是否显示了 Fragment.我怎样才能做到这一点?我尝试通过 Stack Overflow 和 Google 进行搜索,但找不到任何内容.

I want to check if the Activity I create in a test is showing a Fragment. How can I do this? I've tried searching through Stack Overflow and Google but I couldn't find anything.

推荐答案

需要通过 id 和

activity.getFragmentManager.findFragmentById(R.id.your_fragment_container);

如果返回的内容与 null 不同,则表示您的容器具有 Fragment.

If this returns something different from null, then it means that your container has a Fragment.

这篇关于使用 Robolectric 使用 Fragment 测试活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆