how to add a library to testImplementation and androidTestImplementation

1.3k views Asked by At

kotlin library for both test and android tests, unit tests and UI tests.

If I write the bellow two lines as part of build.gradle it works fine.

my question is, is this the right way to add the library to use in both test and android tests

build.gradle

   androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"

Thank you for your valuable suggestions

thanks R

1

There are 1 answers

1
CommonsWare On

is this the right way to add the library to use in both test and android tests

Generally speaking, yes, insofar as you need to have both an androidTestImplementation and a testImplementation statement, even if they are both for the same library.

If you wanted to keep the library in sync, you might define a constant for the library's Maven coordinates:

def mockLibrary = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"

// TODO other good stuff here

dependencies {
// TODO other great libraries here
// TODO OK, maybe a few not-so-great libraries too
  androidTestImplementation mockLibrary
  testImplementation mockLibrary
}