Test dependencies

Currently, there is only one testing library, Junit, which you will use for unit testing. But, since your code will interact with other components, even though they may not be the ones under test, you will have to mock them. Junit is still not enough for writing the test cases. Therefore, you will also need to add Hamcrest to help with creating assertion matches and more. Let's go ahead and add the libraries we will need.

Open your module's build file, update the dependencies to match the following code, and sync the project:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-all:1.10.19"
testImplementation "org.hamcrest:hamcrest-all:1.3"
testImplementation "org.powermock:powermock-module-junit4:1.6.2"
testImplementation "org.powermock:powermock-api-mockito:1.6.2"
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
For now, use the exact library versions as shown in the preceding code. This means you will have to ignore suggestions from the IDE to upgrade your library versions. 

Later, you can update to newer, stable versions which are compatible with each other.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset