我的FragmentActivity
电话:getActionBar()
onCreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_expense);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
当在模拟器或设备上正常运行应用程序时,这可以正常工作。但是,当我用 a 测试 Activity 时ActivityUnitTestCase
,getActionBar()
总是返回 null。
public class NewTransactionTest extends ActivityUnitTestCase<TransactionEditActivity> {
private RenamingDelegatingContext myContext;
private DatabaseHelper myHelper;
private RuntimeExceptionDao<Account,Long> myDao;
private Account myBankAccount1;
private Account myBankAccount2;
private Account myCategory1;
private Account myCategory2;
private Budget myBudget;
public NewTransactionTest() {
super(TransactionEditActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
myContext = new RenamingDelegatingContext(getInstrumentation().getTargetContext(), "test");
myContext.deleteDatabase(DatabaseHelper.DATABASE_NAME);
}
@UiThreadTest
public void testPreConditions() throws Throwable {
setActivityContext(myContext);
final TransactionEditActivity activity = startActivity(new Intent(), null, null);
}
有谁知道为什么getActionBar()
单元测试返回 null ?