I have created a custom view that is used to build a form dynamically. A form configuration is fetched from a server and the custom view then renders a form (edittexts, checkboxes, etc...) based on what is specified in the configuration.

我创建了一个自定义视图,用于动态构建表单。从服务器获取表单配置,然后自定义视图根据配置中指定的内容呈现表单(edittexts,checkboxes等)。

Now I'm trying to figure out how to test the custom view. The view itself extends LinearLayout and follows the MVP pattern so any logic that could be extracted to the Presenter layer has been and is covered under a unit test. Now my goal is to run a UI test to ensure that the view works properly and to find regressions. For example, the server might return a configuration that requires that two EditTexts have character limits of 5 characters. I want to be able to build a form, enter text into the two EditTexts and ensure that their input length has been limited to 5 characters.

现在我想弄清楚如何测试自定义视图。视图本身扩展了LinearLayout并遵循MVP模式,因此任何可以提取到Presenter层的逻辑都已经被单元测试所覆盖。现在我的目标是运行UI测试以确保视图正常工作并查找回归。例如,服务器可能返回一个配置,该配置要求两个EditTexts具有5个字符的字符限制。我希望能够构建一个表单,在两个EditTexts中输入文本,并确保它们的输入长度限制为5个字符。

So what's the proper way to do this?

那么这样做的正确方法是什么?

Is there a way to test just the view itself using instrumentation testing or will the view always need to be in the layout of an activity or fragment in order to test it?

有没有办法使用检测测试只是视图本身,或者视图是否总是需要在活动或片段的布局中进行测试?

1 个解决方案

#1


0

Is there a way to test just the view itself using instrumentation testing or will the view always need to be in the layout of an activity or fragment in order to test it?

有没有办法使用检测测试只是视图本身,或者视图是否总是需要在活动或片段的布局中进行测试?

You cannot test the view separately. During instrumentation test an apk is being built and installed on the device. As you can conclude, your apk cannot consist only of your custom view, it's a normal android application.

您无法单独测试视图。在仪器测试期间,正在构建并安装apk。你可以得出结论,你的apk不能只包含你的自定义视图,它是一个普通的android应用程序。

What you will end up is, that you'd perform actions (e.g. ViewActions.typeText("some text") in EditText with some id) and then perform validations (check, that the EditText with some id has some text as it's content).

你将最终得到的是,你在EditText中用一些id执行动作(例如ViewActions.typeText(“some text”))然后执行验证(检查带有一些id的EditText是否有一些文本作为其内容) 。

As long as you deal with custom view, it's possible that you'd have to create your custom ViewMatcher.

只要您处理自定义视图,就可能需要创建自定义ViewMatcher。

更多相关文章

  1. 关于selenium android下的浏览器测试
  2. 无法将视图添加到相对布局
  3. ListView的上拉弹簧、下拉弹簧,下拉弹簧时动态带刷新和切换换刷新
  4. 在android上滚动时,列表视图的位置会发生变化
  5. 【金阳光测试】Android自动化测试第一季第三讲—Monkey原理初步
  6. 现在做Android开发比较好?还是Android测试?
  7. 【Mac + Appium + Python3.6学习(五)】之常用的Android自动化测
  8. Android Robotium如何管理测试用例的执行顺序?
  9. mac react-native从零开始android真机测试

随机推荐

  1. 用cmake与OpenCV对ARM进行交叉编译
  2. Fatal error: Call to undefined functio
  3. Linux环境下通过pdb调试Python程序
  4. linux 下的时间获取函数
  5. 像wget-like bittorrent客户端还是库?
  6. Android(安卓)照相机实现方式
  7. 疯狂了,Archlinux+Openbox+Rox+fbpanel我
  8. Linux 常用命令使用英文全称
  9. 【Azure】两台Linux虚拟机挂载共享文件
  10. Linux QT5.2下编译MySQL5.6.7驱动