How to setup JUnit in android java project.
1) Use appropriate Android gradle plugin version , gradle version.
If our project is a new project then we can use the latest Android gradle plugin , latest gradle version.
The Android gradle plugin is specified in the project's build.gradle file.
The gradle version is specified in the gradle-wrapper.properties file
However if we are on an existing project, then we do not need to change the Android gradle plugin version, gradle version.
2) Add Junit as a dependency in app build.gradle file
dependencies{
testImplementation 'junit:junit:4.13.2'
}
3) Add a test class in src/test/java in your project as below
public class TrialTest{
@Test
public void testHomeActivityStaticVariables() {
assertEquals(HomeActivity.AppVersion, "1.47");
}
}
4) Now right click on src/test/java and click on
Run Tests