[英]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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.