我正在为我的应用程序开发测试类。测试类代码如下所示:
public class ProfileActivityTest extends ActivityInstrumentationTestCase2<ProfileActivity> {
ProfileActivity profileActivity;
@SuppressLint("NewApi")
public ProfileActivityTest(Class<ProfileActivity> activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
@SuppressLint("NewApi")
public ProfileActivityTest() {
super(ProfileActivity.class);
}
protected void setup() throws Exception {
super.setUp();
profileActivity = getActivity();
}
public void test_profileActivityLoggingIn() {
assertNotNull(profileActivity);
assertEquals(View.GONE, profileActivity.findViewById(R.id.btnAddOrEdit).getVisibility());
}
protected void tearDown() throws Exception {
super.tearDown();
}
}
问题是尽管在setup()中实例化了profileActivity,但我在assertNotNull(profileActivity)上获得了assertionFailure。我不明白我在做什么错;
最佳答案
正如@ njzk2所提到的,“ setup”应更改为“ setUp”。
关于android - 似乎在测试运行时未调用setup(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26363130/