bjoernQ / unmock-plugin

Gradle plugin to be used in combination with the new unit testing feature of the Gradle Plugin / Android Studio to use real classes for e.g. SparseArray.
Apache License 2.0
323 stars 22 forks source link

Allow unmocked classes in any variant #62

Closed cckroets closed 4 years ago

cckroets commented 4 years ago

Previously unmocked classes were added to the testImplementation configuration of each module that needed them. This leads to duplicate work being done by every module that has unit tests. Now there can be a single unmocking module that is included by all other modules.

Usage:

unMock {
    includeInVariants android.libraryVariants
}
zawadz88 commented 4 years ago

Hi @cckroets, Could you explain how

Now there can be a single unmocking module that is included by all other modules.

would work exactly, please? I tried to set up a single module but couldn't get it working... Any tips would be much appreciated :)

E.g. would I still need to apply unmock plugin in each module?

cckroets commented 4 years ago

@zawadz88 Sorry for the late reply. You should only need to apply the unMock plugin to the lower "test-library" module.

E.g. feature-lib and test-utils are two gradle modules. In feature-lib add a dependency on the test utils module

// feature-lib/build.gradle
apply plugin: 'com.android.library'

dependencies {
    testImplementation project(':test-utils')
}

In test-utils apply the unMock plugin

// test-utils/build.gradle
apply plugin: 'com.android.library'
apply plugin: 'de.mobilej.unmock'

unMock {
   // keep ...
   includeInVariants android.libraryVariants
}

Let me know if you are getting a specific error with that setup