Gradle test fixtures plugin for Android development

1.7k views Asked by At

attempting to use gradle test fixtures with gradle 6.6.1, using the following set of plugins

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'org.jetbrains.kotlin.kapt'
apply plugin: 'java-test-fixtures'

produces an error along the lines of

org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method testFixturesApi() for arguments [io.kotest:kotest-property:4.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

(similar results for testFixturesImplementation) Adding the java-library plugin as apparently required by the documentation:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'org.jetbrains.kotlin.kapt'
apply plugin: 'java-test-fixtures'
apply plugin: 'java-library'

yields something along the lines of

The 'java' plugin has been applied, but it is not compatible with the Android plugins.

How can I get gradle testFixtures working when building with kotlin 1.4 (and possibly kotest) for Android on Ubuntu 20.04? My overall intent is to use custom kotest generators for creating property testing fixtures shared among several testing source trees under the same app project, namely

./app/src/test/java
./app/src/androidTest/java

There are good reasons for sharing test helpers in support of code dryness; such approach is not the subject of this discussion; I am not looking for advice in that regard. The goal of this question is a manner to get testFixtures working, since I'm obviously not understanding how to do so, and your help in this direction is much appreciated. I can provide additional details if the above description, deliberately terse, is lacking in necessary detail.

2

There are 2 answers

0
Greg On
apply plugin: 'java-test-fixtures'
apply plugin: 'java-library'

You don't want to put either of those plugins in your application module. The belong in the library module that's producing the fixtures.

0
Nikolay shcheklachev On

They are not supported at android projects, I tested on production project, also created example projects. I have such error

Unable to find a variant of project :modtwo providing the requested capability Fictures:modtwo-test-fixtures:unspecified

It seems they have conflicts with product flavors. Also wrong information here, because in the example it is not an android project.