是否可以使用支持测试库摆脱ActivityInstrumentationTestCase2?(Is it possible to get rid of ActivityInstrumentationT

编程入门 行业动态 更新时间:2024-10-10 13:13:41
是否可以使用支持测试库摆脱ActivityInstrumentationTestCase2?(Is it possible to get rid of ActivityInstrumentationTestCase2 using Support Test Library?)

我正在尝试使用Android Support Test Library (以前的android-test-kit )并为我的一个项目创建测试。 它包含一些“功能”代码以及单个项目中的UI代码。

我的目的是使用JUnit4而不是与JUnit3混合,所以我使用AndroidJUnitRunner 。 为“功能”代码创建了许多测试类,这些代码遵循JUnit4并且工作正常。

最近我开始实现UI组件的测试。 参考文件收据已经实施了测试数量。 这些活动测试遵循JUnit4样式,并基于上述doc扩展ActivityInstrumentationTestCase2 。

我现在面临的问题是:不可能一次执行所有测试。 如果我尝试从IntelliJ Idea运行package / all测试(Activity和'functional'在同一个项目中) - 只执行纯JUnit4测试。 我怀疑问题出在ActivityInstrumentationTestCase2 ,它扩展了TestCase并且不是纯JUnit4测试类。

是否有可能以某种方式在使用Android支持测试库(android-test-kit)的Activity测试中摆脱ActivityInstrumentationTestCase2并且所有测试都在运行? 或者我对问题根源(关于TestCase )的假设是错误的?

I'm trying to use Android Support Test Library (previously android-test-kit) and create tests for one of my projects. It contains some 'functional' code along with UI code in single project.

My intention is to use JUnit4 and not mix with JUnit3, so I use AndroidJUnitRunner. There's number of test classes created for the 'functional' code which follow JUnit4 and work fine.

Recently I've started to implement tests for UI components. Referring documentation receipt number of tests have been implemented. These activity tests follow JUnit4 style and extend ActivityInstrumentationTestCase2 based on above doc.

The problem that I'm facing now: it's not possible to execute all tests at once. If I try to run package / all tests (Activity and 'functional' are presented in the same project) from IntelliJ Idea - only pure JUnit4 tests get executed. I suspect that the problem is in ActivityInstrumentationTestCase2 which extends TestCase and is not pure JUnit4 test class.

Is it possible somehow to get rid of ActivityInstrumentationTestCase2 in Activity tests using Android Support Test Library (android-test-kit) and have all test running? Or my assumption about the issues rootcause (about TestCase) is wrong?

最满意答案

不推荐使用InstrumentationTestCase , ActivityTestCase和ActivityInstrumentationTestCase2 ,您应该使用ActivityTestRule 。 InstrumentationRegistry对于获取应用程序上下文和检测实例也很有用。

Finally found only possible solution: copy InstrumentationTestCase, ActivityTestCase and ActivityInstrumentationTestCase2 into my project from AOSP source. After that, remove inheritance from InstrumentationTestCase of TestCase. Same way it's done in this project (AndroidJunit4). There's actually no need for TestCase and these changes and documentation receipt are enough to have activity tests to be JUnit4 and avoid mixing issues.

更多推荐

本文发布于:2023-08-06 11:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1447643.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   测试   rid   Test   Support

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!