In order to start writing tests for our app, one quick solution could be this one:
1.- Adding junit to our build.gradle file
dependencies{
...
testCompile 'junit:junit:4.12'
}
2.- Creating the test folder structure
This can be done with Android Studio, or directly in your file explorer (finder, nautilus, etc). Create the folder
your_app_folder/app/src/test/java/com/companyname/appname/
where the app’s package name would be com.companyname.appname (substitute by yours).
3.- Creating a sample test
Inside the recently created folder, create a file named ProjectTest.java and copy this content:
public class ProjectTest {
@Test
public void shouldCompare1To1() throws Exception {
assertEquals(1, 1);
}
}
4.- Running the tests in console
Go to terminal, move to your app’s folder and do
./gradlew test
If everything went fine, you should have a single test passing