Write Unit Test class
1. Create a Unit Test folder, which is a new package for unit tests that holds the class for unit tests.
2. Create a class such as exampletest, and note that you want to inherit from the Instrumentationtestcase class.
3. Create a method that starts with test, such as Testjson
To configure unit tests for a project
1. Click "run-> Edit Configurations", then click "+" from the left pop-up list, select Add an Android Tests, then rename it to the desired name in the upper right corner.
2. Select your current module, such as app, from the drop-down menu.
3. Select the "All on package" option, and then select the test folder you just created. You can also select the "All in Module" option so that Android Studio will automatically find all the test units in your entire module, and you can also specify a class or even a test method with another option.
When configured, it resembles the following.
4. You should now see that the test case has been configured as a running project on the toolbar above Android studio, as shown in:
Run unit Tests
1. Select the Unit test item and click Run ...
2. Right-click the method you want to run, click Run ...
Unit testing can be done in Android studio