# Unit tests **Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation.** Our Unit tests are based on JUnit and are located under `/src/test/java/`. We are using plain JUnit to test classes that aren't calling the Android API, or are using Android's JUnit extensions to stub/mock Android components. ## Writing unit tests Unit tests for an Android project are located in the `test` folder: screen shot 2016-03-16 at 17 24 31 To add a test, right click the corresponding package and select create new `Java class`. Name the class appropriately by ending it with `Test` and start adding test methods by applying the `@Test` annotation: ```java package com.mapbox.mapboxsdk.annotations; import org.junit.Test; public class AwesomeSauceTest { @Test public void simpleTest(){ } } ``` you can add methods that are executed before and after each test: ```java package com.mapbox.mapboxsdk.annotations; import org.junit.After; import org.junit.Before; import org.junit.Test; public class AwesomeSauceTest { @Before public void beforeEachTest(){ } @Test public void simpleTest(){ } @After public void afterEachTest(){ } } ``` ## Running unit tests You can run a test locally by right clicking and selecting run: screen shot 2016-03-16 at 17 46 09 If you like, you can also run with test coverage enabled. This will show you the following dialog: screen shot 2016-03-16 at 17 58 34 You can also run the tests from the command line with: ``` $ ./gradlew -Pmapbox.abis=none test -p MapboxGLAndroidSDKTestApp ``` ## Running Unit tests on CI The Unit tests are executed as part of the build process on our CI and are automatically run for each new commit pushed to this repo. If a Unit tests fails, this will fail and stop the build. You can find this gradle command in our [buildscript](https://github.com/mapbox/mapbox-gl-native/blob/master/circle.yml#L146-L215): ``` $ ./gradlew -Pmapbox.abis=none testReleaseUnitTest ``` ## Code Coverage Showing code coverage directly in the IDE. - Switch your Build Variant to the Unit Tests artifact - Right click a unit test and select `Run test with coverage` - Select `Add to active suites` //this will create a run configuration - Edit the run configuration to include/exclude packages in the `Code coverage`-tab.