You will need to import some dependencies for both Spring and Android. Here are the dependencies.
- Spring
To implement the dependency for testing, you need to add the testing dependency in the pom.xml file:
<!-- This is to implement the testing functions for the spring project -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
- Android
To test an Android project, we need to implement the testing dependencies in the gradle file. To add the dependencies, we need to implement in the dependencies {...} of build.gradle (app module) file. Here is a snippet code of this build.gradle file:
// Dependencies for local unit tests
dependencies{
testImplementation "junit:junit:$rootProject.ext.junitVersion"
// Espresso UI Testing dependencies.
androidTestImplementation "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestImplementation "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
}
The source code with an example for this chapter is available on GitHub at the following link: https://github.com/PacktPublishing/Learn-Spring-for-Android-Application-Development/tree/master/Chapter10.