English 中文(简体)
活动测试——测试
原标题:Android Activity Tests - Testing Restarts

rel=“nofollow”测试,题为“Adding state management test”的章节,见《乐器开发文件》,它建议重新启动活动:

mActivity.finish();
mActivity = this.getActivity();

Having tried this with the addition of a sleep between the two statements above, I can see that the Activity is not redrawn on the screen when the mActivity = this.getActivity() is executed. My test appears to work, but I am intrigued as to why the Activity isn t redrawn on the screen as this doesn t seem to be mentioned in the API documentation.

我感谢大家对这一看法的任何见解。 在要求采用“完成”方法时,活动从屏幕上消失,但在此时此刻不再发生。 要求采取行动。 我也试图在行为发生后将一种行为性。

My code snippet is now:

...
mActivity.finish();
Thread.sleep(5000);
mActivity = this.getActivity();
Thread.sleep(5000);
...

我进行了广泛的搜索,但找不到任何解释,说明为什么在要求采取主动时活动不会再发生。

我在2.3.5、2.3.3和2.2中测试了所有结果。

问题回答

看来,班级活动入侵试验Case2需要一种额外的完成方法,其中必须进行一些清理。 与此同时,在完成这项活动之后,你可以通过清理雨水来解决这一问题。 从而改变你的法典如下:

mActivity.finish();
setActivity(null);
mActivity = this.getActivity();

可解释如下。 班级活动干预方法

public T getActivity() {
    Activity a = super.getActivity();
    if (a == null) {
        // set initial touch mode
        getInstrumentation().setInTouchMode(mInitialTouchMode);
        final String targetPackage = 
            getInstrumentation().getTargetContext().getPackageName();
        // inject custom intent, if provided
        if (mActivityIntent == null) {
            a = launchActivity(targetPackage, mActivityClass, null);
        } else {
            a = launchActivityWithIntent(targetPackage, 
                                         mActivityClass, 
                                         mActivityIntent);
        }
        setActivity(a);
    }
    return (T) a;
}

方法的确定性确定内部可变性。

public void setActivityIntent(Intent i) {
    mActivityIntent = i;
}

第一次呼吁之后的所有呼吁现在都将使用新的价值性主动性,而不是无价值。 结果

a = launchActivityWithIntent(targetPackage, mActivityClass, mActivityIntent);

will be called. Probably your app can not be started with this intent.

注:方法后方 Down:

protected void tearDown() throws Exception {
    // Finish the Activity off (unless was never launched anyway)
    Activity a = super.getActivity();
    if (a != null) {
        a.finish();
        setActivity(null);
    }
}




相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签