【发布时间】:2014-02-06 09:30:53
【问题描述】:
我有几个需要测试的 PreferenceFragment 类:
public class MyPref extends PreferenceFragment
如何测试它们?
例如我尝试过:
public class MyPrefTester extends ActivityInstrumentationTestCase2<MyPref>
但是这失败了,因为这个 Android 测试类要求参数继承自 Activity。并且 PreferenceFragment 继承自 Fragment(由 Activity 使用)。
有什么建议?
【问题讨论】:
-
不知道大家是否熟悉 Model-View-Presenter 模式,但是如果 Fragment 在接口后面,单独测试 Presenter 逻辑会更容易。
-
您正在尝试在片段上使用 ActivityInstrumentationTestCase2。这显然行不通,而是在 Activity 上使用它。
标签: android unit-testing junit preferencefragment