assertNotNull()的junit.framework.AssertionFailedError

时间:2014-04-08 06:36:56

标签: android eclipse junit

我对Android JUnit测试没有多少经验。在这里,我正在为JUnit做一个简单的测试应用程序。当第一个活动Intent中按下的按钮用于启动第二个活动时,应用程序包含两个活动。但我得two failuresjunit.framework.AssertionFailedError。这是我尝试过的代码:

public void testLayout(){
        buttonId=com.example.androidunittest.R.id.button;
        assertNotNull(activity.findViewById(buttonId));
        Button view=(Button) activity.findViewById(buttonId);
        assertEquals("Incorrect label of the button","Start",view.getText());
    }

    public void testIntentTriggerViaOnClick(){
        buttonId=com.example.androidunittest.R.id.button;
        Button view=(Button) activity.findViewById(buttonId);
        assertNotNull("Button not allowed to be null",view);
            view.performClick();
            Intent triggeredIntent=getStartedActivityIntent();
        assertNotNull("Intent was null",triggeredIntent);
        String data=triggeredIntent.getExtras().getString("URL");

        assertEquals("Incorrect data passed via the intent","http://www.google.com", data);
}

失败线是 根据JUnit测试面板结果,assertNotNull("Button not allowed to be null",view);assertNotNull(activity.findViewById(buttonId));

有人可以解释一下这里发生了什么吗?另外如何修复应用程序代码中的错误?

我有另一个问题,如何在eclipse中运行所有测试类一次?  我所做的是按照answer,右键点击项目 - >运行as-> Android JUnit测试。但只有活跃的班级给出了结果。

任何帮助将不胜感激。

0 个答案:

没有答案
相关问题