似乎在测试运行时不调用setup()

时间:2014-10-14 14:18:42

标签: android android-activity android-testing

我正在为我的应用程序开发一个测试类。测试类代码如下所示:

   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();
      }
}

问题是我在assertNotNull(profileActivity)上获得了assertionFailure,尽管在setup()中实例化了profileActivity。我不明白我做错了什么;

1 个答案:

答案 0 :(得分:1)

正如@ n​​jzk2所说,“setup”应该改为“setUp”。