Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 由于';java.lang.IllegalArgumentException';_Android_Junit_Android Testing_Gui Testing - Fatal编程技术网

Android 由于';java.lang.IllegalArgumentException';

Android 由于';java.lang.IllegalArgumentException';,android,junit,android-testing,gui-testing,Android,Junit,Android Testing,Gui Testing,我试图在我的类上执行一个简单的测试,以测试按下按钮时是否启动了正确的下一个活动 在我的类中,根据用户是经理还是其他用户,启动不同的活动 这是我的测试类中的代码: package com.footballadmin.ssfc.test; import org.junit.Test; import android.app.Activity; import android.app.Instrumentation.ActivityMonitor; import android.test.Activi

我试图在我的类上执行一个简单的测试,以测试按下按钮时是否启动了正确的下一个活动

在我的类中,根据用户是经理还是其他用户,启动不同的活动

这是我的测试类中的代码:

package com.footballadmin.ssfc.test;

import org.junit.Test;

import android.app.Activity;
import android.app.Instrumentation.ActivityMonitor;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.ImageView;

import com.footballadmin.ssfc.ApplicationMenu;
import com.footballadmin.ssfc.Calendar;
import com.footballadmin.ssfc.ManagerMenu;
import com.footballadmin.ssfc.R;

public class CalendarTest extends ActivityInstrumentationTestCase2<Calendar> {

    private ImageView menu;
    private Calendar mActivity;
    private String userEmail, managerEmail;



public CalendarTest() {
        super("com.footballadmin.ssfc.test", Calendar.class);
    }


    protected void setUp() throws Exception {
        super.setUp();
        mActivity = getActivity();
        userEmail = "test@test.com";
        managerEmail = "cstewart@gmail.com";
        menu = (ImageView) mActivity.findViewById(R.id.calendar_menu_icon);
    }

    public void testPreConditions() {
        assertTrue (menu != null);
    }

    //test Menu Button for manager
        @Test
        public void testCalendarMenuButtonIfUserIsManager() {

            mActivity.currentUserEmail = managerEmail;
            ActivityMonitor activityMonitor =   getInstrumentation().addMonitor(ManagerMenu.class.getName(), null, false);

            mActivity = getActivity();
            menu = (ImageView) mActivity.findViewById(R.id.calendar_menu_icon);

            mActivity.runOnUiThread(
                    new Runnable() {
                        public void run() {


                            menu.requestFocus();
                            menu.performClick();

                        }

                    });

            Activity nextActivity = getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 15);
            assertNotNull(nextActivity);
            nextActivity.finish();              

        }


        //testMenuButton for general user
        @Test
        public void testCalendarMenuButtonIfUserIsUser() {

            mActivity.currentUserEmail = userEmail;
            ActivityMonitor activityMonitor = getInstrumentation().addMonitor(ApplicationMenu.class.getName(), null, false);

            mActivity = getActivity();
            menu = (ImageView) mActivity.findViewById(R.id.calendar_menu_icon);

            mActivity.runOnUiThread(
                    new Runnable() {
                        public void run() {


                            menu.requestFocus();
                            menu.performClick();

                        }
                    });

            Activity nextActivity = getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 15);
            assertNotNull(nextActivity);
            nextActivity .finish();


        }

        //STUB test if news is populated
        @Test
        public void testCalendarIsPopulated(){

        }

}
当我运行这个测试类时,我在LogCat中得到以下信息:

    03-31 06:48:58.381: E/WindowManager(1066): Activity com.footballadmin.ssfc.Calendar has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4182e0d0 V.E..... R.....ID 0,0-456,144} that was originally added here
    03-31 06:48:58.381: E/WindowManager(1066): android.view.WindowLeaked: Activity com.footballadmin.ssfc.Calendar has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4182e0d0 V.E..... R.....ID 0,0-456,144} that was originally added here
    03-31 06:48:58.381: E/WindowManager(1066):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.Dialog.show(Dialog.java:281)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.footballadmin.ssfc.Calendar$LoadCalendar.onPreExecute(Calendar.java:175)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.AsyncTask.execute(AsyncTask.java:534)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.footballadmin.ssfc.Calendar.onResume(Calendar.java:97)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.Activity.performResume(Activity.java:5211)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2780)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.Handler.dispatchMessage(Handler.java:99)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.Looper.loop(Looper.java:137)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.main(ActivityThread.java:5103)
    03-31 06:48:58.381: E/WindowManager(1066):  at java.lang.reflect.Method.invokeNative(Native Method)
    03-31 06:48:58.381: E/WindowManager(1066):  at java.lang.reflect.Method.invoke(Method.java:525)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    03-31 06:48:58.381: E/WindowManager(1066):  at dalvik.system.NativeStart.main(Native Method)

And the following in the JUnit window:

    junit.framework.AssertionFailedError
    at     com.footballadmin.ssfc.test.CalendarTest.testCalendarMenuButtonIfUserIsManager(CalendarTest.java:61)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
    at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
    at   android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
03-31 06:48:58.381:E/WindowManager(1066):Activity com.footballdmin.ssfc.Calendar泄漏了最初添加到此处的window com.android.internal.policy.impl.PhoneWindow$DecorView{4182e0d0 V.E..R..ID 0,0-456144}
03-31 06:48:58.381:E/WindowManager(1066):android.view.WindowLeaked:Activity com.footballdmin.ssfc.Calendar泄漏了最初添加到此处的window com.android.internal.policy.impl.PhoneWindow$DecorView{4182e0d0 V.E..R..ID 0,0-456144}
03-31 06:48:58.381:E/WindowManager(1066):在android.view.ViewRootImpl。(ViewRootImpl.java:345)
03-31 06:48:58.381:E/WindowManager(1066):在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
03-31 06:48:58.381:E/WindowManager(1066):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.Dialog.show(Dialog.java:281)
03-31 06:48:58.381:E/WindowManager(1066):位于com.footballadmin.ssfc.Calendar$LoadCalendar.onPreExecute(Calendar.java:175)
03-31 06:48:58.381:E/WindowManager(1066):位于android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
03-31 06:48:58.381:E/WindowManager(1066):在android.os.AsyncTask.execute(AsyncTask.java:534)
03-31 06:48:58.381:E/WindowManager(1066):位于com.footballadmin.ssfc.Calendar.onResume(Calendar.java:97)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.Activity.performResume(Activity.java:5211)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2780)
03-31 06:48:58.381:E/WindowManager(1066):位于android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.ActivityThread.access$600(ActivityThread.java:141)
03-31 06:48:58.381:E/WindowManager(1066):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-31 06:48:58.381:E/WindowManager(1066):在android.os.Handler.dispatchMessage(Handler.java:99)上
03-31 06:48:58.381:E/WindowManager(1066):在android.os.Looper.loop(Looper.java:137)
03-31 06:48:58.381:E/WindowManager(1066):位于android.app.ActivityThread.main(ActivityThread.java:5103)
03-31 06:48:58.381:E/WindowManager(1066):位于java.lang.reflect.Method.Invokenactive(本机方法)
03-31 06:48:58.381:E/WindowManager(1066):位于java.lang.reflect.Method.invoke(Method.java:525)
03-31 06:48:58.381:E/WindowManager(1066):位于com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-31 06:48:58.381:E/WindowManager(1066):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-31 06:48:58.381:E/WindowManager(1066):在dalvik.system.NativeStart.main(本机方法)
以及JUnit窗口中的以下内容:
junit.framework.AssertionFailedError
在com.footballadmin.ssfc.test.CalendarTest.testCalendarMenuButtonIfUserIsManager(CalendarTest.java:61)上
位于java.lang.reflect.Method.Invokenactive(本机方法)
位于android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
位于android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
位于android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
位于android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
位于android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
位于android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
位于android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
对我的问题有什么想法吗

非常感谢

    03-31 06:48:58.381: E/WindowManager(1066): Activity com.footballadmin.ssfc.Calendar has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4182e0d0 V.E..... R.....ID 0,0-456,144} that was originally added here
    03-31 06:48:58.381: E/WindowManager(1066): android.view.WindowLeaked: Activity com.footballadmin.ssfc.Calendar has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4182e0d0 V.E..... R.....ID 0,0-456,144} that was originally added here
    03-31 06:48:58.381: E/WindowManager(1066):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.Dialog.show(Dialog.java:281)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.footballadmin.ssfc.Calendar$LoadCalendar.onPreExecute(Calendar.java:175)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.AsyncTask.execute(AsyncTask.java:534)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.footballadmin.ssfc.Calendar.onResume(Calendar.java:97)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.Activity.performResume(Activity.java:5211)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2780)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.Handler.dispatchMessage(Handler.java:99)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.os.Looper.loop(Looper.java:137)
    03-31 06:48:58.381: E/WindowManager(1066):  at android.app.ActivityThread.main(ActivityThread.java:5103)
    03-31 06:48:58.381: E/WindowManager(1066):  at java.lang.reflect.Method.invokeNative(Native Method)
    03-31 06:48:58.381: E/WindowManager(1066):  at java.lang.reflect.Method.invoke(Method.java:525)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    03-31 06:48:58.381: E/WindowManager(1066):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    03-31 06:48:58.381: E/WindowManager(1066):  at dalvik.system.NativeStart.main(Native Method)

And the following in the JUnit window:

    junit.framework.AssertionFailedError
    at     com.footballadmin.ssfc.test.CalendarTest.testCalendarMenuButtonIfUserIsManager(CalendarTest.java:61)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
    at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
    at   android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)