Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为我的活动编写测试
MyActivity activity = new MyActivity(); activity.onCreate(null);
我的活动需要传递额外的参数,所以当我调用 onCreate 时它会崩溃。如何在不使用 Intent 的情况下将额外内容传递给我的活动?
您可以让被测活动对额外参数使用一些默认值,但我不推荐这种方法。相反,只需让测试通过值。
来自http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html#setActivityIntent(android.content.Intent)
在第一次调用 getActivity() 之前调用此方法,将自定义 Intent 注入到被测 Activity 中。