在 Android 开发人员中,我看到 testPreconditions() 方法应该在所有测试之前启动。但在我的应用测试中,它就像一个正常的测试。它不会在所有测试之前运行。有什么不对 ?
以下是 android developer 对 testPreconditions() 的描述:“先决条件测试在执行其他测试之前检查初始应用程序条件。它类似于 setUp(),但开销较小,因为它只运行一次。”
在 Android 开发人员中,我看到 testPreconditions() 方法应该在所有测试之前启动。但在我的应用测试中,它就像一个正常的测试。它不会在所有测试之前运行。有什么不对 ?
以下是 android developer 对 testPreconditions() 的描述:“先决条件测试在执行其他测试之前检查初始应用程序条件。它类似于 setUp(),但开销较小,因为它只运行一次。”
实际上, testPreconditions() 只是另一个单元测试。以下是 Diego Torres Milano 的一本书“Android 应用程序测试指南”的引述:
" testPreconditions 方法此方法用于检查一些初始条件以正确运行我们的测试。尽管它的名称,但不能保证此测试在其他测试之前运行。但是,收集所有先决条件是一个好习惯使用此自定义名称进行测试。”
米兰,迭戈·托雷斯 (2011-06-23)。Android 应用程序测试指南(第 76 页)。包出版。Kindle版。
根据 Android SDK 示例:
The name 'test preconditions' is a convention to signal that if this test doesn't pass, the test case was not set up properly and it might explain any and all failures in other tests. This is not guaranteed to run before other tests, as junit uses reflection to find the tests.
确保您从正确的类 (ActivityInstrumentationTestCase2) 继承,并且您的方法签名匹配:
public void testPreconditions()