InstrumentationTestCase和AndroidTestCase的区别

7
我一直在研究这个答案:https://dev59.com/vXI-5IYBdhLWcg3wBjnl#2055455,它很好地解释了Android中可用于单元/集成测试的不同测试类。但是,它没有解释InstrumentationTestCase和其他测试用例类(特别是AndroidTestCase)之间的区别。
有人能够解释一下吗?
1个回答

8

根据文档:

InstrumentationTestCase

具有访问 Instrumentation 权限的测试用例。

AndroidTestCase

如果需要访问资源或其他依赖于 Activity 上下文的内容,请扩展此类。

AndroidTestCase 可以通过您发布的链接进行很好地概括。 InstrumentationTestCase 位于 ActivityInstrumentationTestCase2 的类层次结构较高处。它比普通的 AndroidTestCase 更重,但仅公开一个 Instrumentation 对象而没有 Activity,从而限制了其实用性。

实际上,您可能永远不需要使用此类,因为它与 ActivityInstrumentationTestCase2 相比没有(如果有)任何性能优势,后者本身就可以访问 Instrumentation 对象。无论如何,如果想要知道可以使用 Instrumentation 对象做什么,请查看此链接此链接


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接