我想运行单元测试和espresso测试用例特定的构建类型 [英] I want to run unit test and espresso test cases a specific build type

查看:140
本文介绍了我想运行单元测试和espresso测试用例特定的构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多变量和多构建类型的项目..有一些espresso和单元测试用例运行成功,但成功运行我嘲笑我的api响应目前我在android工作室中手动更改我的构建类型,然后运行这些测试。现在我正在将我的项目与jenkins集成在一起,并且在jenkins中,我的测试失败了,因为jenkins正在所有构建类型上运行测试用例。所以很长的故事Short我希望我的测试用例仅使用分段构建类型运行..

解决方案

正如 android测试支持风格和构建类型变体?,您可以创建 androidTest test 特定口味的文件夹。你也可以扩展它来构建类型。 Gradle允许你为任何特定的构建类型和风格组合构建测试。



假设您有两种构建类型( staging debug )和两种风格( trial 完整)。以下所有文件夹都是有效的文件夹名称:


  • src / androidTestStaging 运行所有风格的 staging build

  • src / testFull - 测试使用完整 flavor

  • src / androidTestTrialDebug 只运行试用版 调试版构建版

  • src / testFullStaging - 仅在完整> 停滞 build



这些文件夹中的每一个都具有与 androidTest 和<$ c完全相同的目录结构$ c> test 分别。每个文件夹中的测试只会针对由所有指定的构建类型和风格构建而成的构建运行。



请注意,这可以迅速爆炸成很多组合。例如,如果您有3种构建类型和2种风味维度,每种风味有3种风格,则您现在有27种不同的构建。维护这些测试可能是一场噩梦,因此您仍然应该遵循标准的软件工程实践来编写测试和帮助程序类以及可以尽可能重用的函数。

I have a multiple falvoured and multiple build type project..having some espresso and unit test cases which are running successfully but to run them successfully i have mocked my api responses currently i change my build type manually in android studio to stagging and then run those tests. Now i am integrating my project with jenkins and in jenkins my tests failed becuase jenkins is running test cases on all build types.. So long story Short I want my test cases to run only using staging build type..

解决方案

As stated in android test support flavors and build type variants?, you can create androidTest and test folders for specific flavors. You can also extend this to build types. Gradle allows you to build tests for any specific combination of build-type and flavor.

Let's say you have two build types (staging and debug) and two flavors (trial and full). All of the following are valid folder names:

  • src/androidTestStaging - tests to run for all flavors of staging build
  • src/testFull - tests to run for all builds with full flavor
  • src/androidTestTrialDebug - tests to run on only trial flavor of debug build
  • src/testFullStaging - tests to run on only full flavor of stagins build

Each of these folders have the exact same directory structure as androidTest and test respectively. The tests in each folder will only be run against a build which is made from all of the specified build types and flavors.

Note that this can quickly explode into a lot of combinations. For example, if you have 3 build types and 2 flavor dimensions with 3 flavors each, you now have 27 different builds. Maintaining tests for each of these can be a nightmare, so you should still follow standard software engineering practices to write tests and helper classes and functions that can be reused as much as possible.

这篇关于我想运行单元测试和espresso测试用例特定的构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆