Android工具测试,用于库模块覆盖率 [英] Android instrumentation tests for library module coverage

查看:85
本文介绍了Android工具测试,用于库模块覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个android项目来为其设置代码覆盖率.我没有为Android做太多事情,也没有做太多事情,所以我着手寻找一个有用的教程.令人惊讶的是,前几篇教程非常有帮助,我能够包括jacoco gradle插件并启用代码覆盖范围.使用詹金斯,我什至生成了一份覆盖率报告.到目前为止,一切看起来都很好.

I inherited an android project to setup code coverage for. Not having done much for android and almost as little in gradle, I embarked on a quest to find a helpful tutorial. As surprises go, the first few tutorials were very helpful and I was able to include the jacoco gradle plugin and enable the code coverage. Using jenkins I even generated a coverage report. So far everything looks fine.

但是,当我着眼于报告时,我闻到了腥味.测试与覆盖率似乎太小.进一步调查发现了罪魁祸首.

However, upon setting my eyes on the report, I smelled something fishy. The test vs coverage ratio seemed to be far too small. Further investigation revealed the culprit.

测试本身更多是作为功能而不是单元测试来编写的.没关系的但是,项目库的模块中没有测试.相反,库测试是在gui模块中编写的(因为使用了库).

The tests itself are written more as functional not unit ones. That would be ok. However, the project library has no tests in its module. Instead the library tests are written in the gui module (as that is where the library is used).

因此,即使测试涵盖了大多数库功能,但覆盖范围仅是从gui模块生成的.

Therefore, even though most of the library functionality is covered by tests, coverage is generated for stuff from gui module only.

项目

-Gui模块

---- gui来源

---- gui sources

----所有测试

-库模块

----库资源

不,我一直在寻找可行的解决方案.不幸的是,我只能找到如何将单元和集成.exec测试覆盖率结果合并为一份报告(或其他基于单元测试的解决方案-都不适用于仪器的解决方案).

No I have been looking for a working solution quite some time. Unfortunately, all I was able to find was how to combine unit and integration .exec test coverage results into one report (or other unit test based solutions - none of which worked for the instrumentation ones).

我需要的是根据Gui模块测试为Library模块的源生成覆盖率.

What I need, is generate coverage for sources from Library module based on Gui module tests.

当我在黑暗中跌跌撞撞时,像这样的事情是否遥不可及?

As I am stumbling in a dark here, is even anything like that, remotely possible?

推荐答案

对于阅读本文档的任何人……如果您遇到同样的问题,是时候开始将头撞墙了……

For anyone reading this... if you have the same issue, it is time to start banging your head against the wall...

今天我很幸运地偶然发现了这个问题: https://issuetracker.google.com/issues/37004446#comment12

Today I was lucky enough to stumble upon this: https://issuetracker.google.com/issues/37004446#comment12

实际的问题"似乎是,库项目始终是发行类型的.因此,它们不包含必要的工具设置"(除非您也为发布启用了代码覆盖,尽管我尚未对其进行测试).

The actual "problem" seems to be, that library projects are "always" of release type. Therefore they do not contain "necessary instrumentation setup" (unless you enable code coverage for release as well, although I haven't tested it).

因此解决方案是在要发布的库中专门启用调试"构建(如前所述,默认为发布类型):

So the solution is to specifically enable, in the library to be published, "debug" build (as mentioned, default is the release type):

android { 
        publishNonDefault true 
} 

然后,在使用库的项目中,指定debugCompile依赖项(发行版编译可以使用默认"发行版配置):

Then, in the project that uses library, specify a debugCompile dependency (release compile can use the "default" release configuration):

dependencies { 
        debugCompile project(path: 'library', configuration: 'debug') 
        releaseCompile project('library') 
} 

当然(我认为这是理所当然的),请记住启用该库的测试覆盖范围:

And of course (this one I take for granted), remember to enable test coverage for the library:

android { 
        buildTypes { 
                debug { 
                        testCoverageEnabled true 
                } 
        } 
} 

这篇关于Android工具测试,用于库模块覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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