I am using Android Studio 1.2
Say I have a simple method add in some class MyAdder
public int add(int a,int b) {
return a+b;
}
I want to perform the unit test and use assertions to perform the test for the above-mentioned code.
I found it tough, to begin with, Testing Fundamentals from the official DEV site so a sample code or a detailed tutorial for performing unit tests would be appreciated.
Two types of tests are supported, available in a drop-down menu in the
Build Variants
tool window of Android Studio:The Testing Fundamentals page mostly discusses Android Instrumentation Tests, with which, as you noted, is a bit tough to get started.
For your question, however, you just need Unit Tests.
From the Unit testing support page:
Here is some sample code to test the instance method in your question (replace
com/domain/appname
with the path created by your package name):projectname/app/src/test/java/com/domain/appname/MyAdderTest.java