Android instrumentation tests for library module coverage

前端 未结 1 1815
时光取名叫无心
时光取名叫无心 2021-02-08 10:28

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

1条回答
  •  星月不相逢
    2021-02-08 11:14

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

    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 
    } 
    

    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 
                    } 
            } 
    } 
    

    0 讨论(0)
提交回复
热议问题