简体   繁体   English

结合Android工具测试和后端集成测试

[英]Combine Android instrumentation tests and backend integration tests

I manage unit tests and integration tests for a complex Spring-based backend project. 我管理一个基于Spring的复杂后端项目的单元测试和集成测试。 The tests should be extended by end-to-end test which check the interaction between the backend and Android clients. 应通过端到端测试扩展测试,该测试将检查后端和Android客户端之间的交互。

A simple test case whould be "When an event is triggered on the backend server, there should be a notification shown on the device" . 一个简单的测试用例应该是“当后端服务器上触发事件时,设备上应该显示通知”

The first thing I tried was implementing Android instrumentation tests but hit a wall when it comes to the backend interaction. 我尝试的第一件事是实施Android工具测试,但在涉及后端交互时遇到了麻烦。 Tests include calls to many different services and remote database operations and I feel this heavy liftig should not happen on the Android device. 测试包括对许多不同服务和远程数据库操作的调用,我觉得这种繁琐的举动不应该在Android设备上发生。 Another issue is that making the current Spring test environment work in an Android environment is a huge PITA. 另一个问题是,使当前的Spring测试环境在Android环境中运行是一个巨大的PITA。

The second thing I tried was integrating calls to Android's build tool gradle into my test logic. 我尝试的第二件事是将对 Android构建工具gradle的调用集成到我的测试逻辑中。 This means I executed a command line call like ./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=MyTestClass#notificationCheck and checked the call for a positive execution result. 这意味着我执行了./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=MyTestClass#notificationCheck类的命令行调用,并检查了该调用的执行结果。 This produced somewhat correct test results but felt very sluggish because of the rather long execution times of the command line calls. 这产生了一些正确的测试结果,但是由于命令行调用的执行时间较长,因此感觉很迟钝。

I use the Android UI Automator library for cross-application testing. 我使用Android UI Automator库进行跨应用程序测试。 Mocking calls to and from the backend on the Android device is not an option. 不能在Android设备上模拟往返于后端的呼叫。

How can I include Android instrumentation checks in my plain integration tests to create end-to-end tests? 如何在我的普通集成测试中包括Android工具检查以创建端到端测试? What are technical solutions for this? 有哪些技术解决方案? Do solutions for such a scenario already exist? 是否存在针对这种情况的解决方案?

A sample test could look like this: 样本测试如下所示:

class NotificationEventTest{
    @Autowired
    private MyService service;

    private AndroidDevice device = AndroidDevice.getConnectedDevice();

    @Test
    public void notificationEventTest(){
        service.createEvent();
        boolean success = device.checkNotification(); //instrumentation
        assertThat(success).isTrue();
    }
}

I found Appium which matches my requirements. 我找到了符合我要求的Appium Executing some heavyweight backend tests and at the same time asserting responses on a device is perfectly possible. 执行某些重量级后端测试并同时断言设备上的响应是完全可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio中的Robolectric和Instrumentation测试 - Robolectric and Instrumentation tests in Android Studio IllegalAccessError运行android工具测试 - IllegalAccessError running android instrumentation tests Maven不会运行Android工具测试 - Maven won't run Android instrumentation tests Android Instrumentation测试Parxally失败的androidx orchestrator - Android Instrumentation Tests Paritally Failing with androidx orchestrator Android JUnit4 Instrumentation测试上没有可运行的方法 - No runnable methods on Android JUnit4 Instrumentation Tests Android 仪器测试:“找不到测试类”使用 Espresso 和 Spoon - Android Instrumentation Tests: 'Could not find test class' using Espresso and Spoon 运行Android Instrumentation测试时“无法确定扩展文件夹” - “Cannot determine expansion folder” when running android Instrumentation tests 仪表测试将作为本地单元测试在Android Studio 3(空测试套件)上运行 - Instrumentation Tests will run as Local Unit tests on Android Studio 3 (Empty test suite) 使用相同的集成测试来测试多个android应用程序? - Test multiple android applications with same integration tests? 如何为成熟的Android应用程序运行集成测试? - How to run integration tests for a mavenised Android application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM