Android JUnit Test不起作用

时间:2015-02-19 17:45:14

标签: android testing junit

我是Android JUnit Testing的新手,我正在尝试使用我的StartActivity。但即使最简单的测试也行不通:

public class testMain extends ActivityUnitTestCase<MainActivity> {

     private MainActivity activity;
    private int buttonId;


    public testMain() {
            super(MainActivity.class);
          }


     @Override
    protected void setUp() throws Exception {
        // TODO Auto-generated method stub
        super.setUp();
        Intent intent = new Intent(getInstrumentation().getTargetContext(),
                MainActivity.class);
            startActivity(intent, null, null);
            activity = getActivity();
    }

     public void testOverViewButton() {

            try {
                /*
                buttonId = com.example.myexpenses.R.id.btnOverview;
                assertNotNull(activity.findViewById(buttonId));
                Button view = (Button) activity.findViewById(buttonId);
                assertEquals("Incorrect label of the button", "Übersicht",
                        view.getText());
                        */
                final String  hallo = "HalloWelt";
                assertEquals("HalloWelt", hallo); //Assert fails, and code
                                                  //above this, fails too                       
            } catch (Exception e) {
                fail();
                System.out.println(e.getMessage());
            }
          }

}

我的LogCat文件如下所示:

02-19 17:29:50.270: E/memtrack(2410): Couldn't load memtrack module (No such file or directory)
02-19 17:29:50.270: E/android.os.Debug(2410): failed to load memtrack module: -2
02-19 17:29:50.298: E/art(2410): Thread attaching while runtime is shutting down: Binder_1
02-19 17:29:50.679: E/memtrack(2420): Couldn't load memtrack module (No such file or directory)
02-19 17:29:50.679: E/android.os.Debug(2420): failed to load memtrack module: -2
02-19 17:29:50.737: E/art(2420): Thread attaching while runtime is shutting down: Binder_1
02-19 17:29:51.211: E/memtrack(2430): Couldn't load memtrack module (No such file or directory)
02-19 17:29:51.211: E/android.os.Debug(2430): failed to load memtrack module: -2
02-19 17:29:51.304: E/libprocessgroup(2441): failed to make and chown /acct/uid_10045: Read-only file system
02-19 17:29:52.430: E/memtrack(2457): Couldn't load memtrack module (No such file or directory)
02-19 17:29:52.430: E/android.os.Debug(2457): failed to load memtrack module: -2
02-19 17:29:52.514: E/libprocessgroup(2468): failed to make and chown /acct/uid_10045: Read-only file system
02-19 17:29:52.617: E/art(2468): Failed sending reply to debugger: Broken pipe

我如何获得更多信息? 为什么断言失败: final String hallo =&#34; HalloWelt&#34 ;; assertEquals(&#34; HalloWelt&#34;,hallo);

THX。

0 个答案:

没有答案