1# Wifi Unit Tests 2This package contains unit tests for the android wifi service based on the 3[Android Testing Support Library](http://developer.android.com/tools/testing-support-library/index.html). 4The test cases are built using the [JUnit](http://junit.org/) and [Mockito](http://mockito.org/) 5libraries. 6 7## Running Tests 8The easiest way to run tests is simply run 9 10``` 11frameworks/opt/net/wifi/tests/wifitests/runtests.sh 12``` 13 14`runtests.sh` will build the test project and all of its dependencies and push the APK to the 15connected device. It will then run the tests on the device. 16 17See below for a few example of options to limit which tests are run. 18See the 19[AndroidJUnitRunner Documentation](https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html) 20for more details on the supported options. 21 22``` 23runtests.sh -e package com.android.server.wifi.util 24runtests.sh -e class com.android.server.wifi.WifiServiceImplTest 25``` 26 27If you manually build and push the test APK to the device you can run tests using 28 29``` 30adb shell am instrument -w 'com.android.server.wifi.test/androidx.test.runner.AndroidJUnitRunner' 31``` 32 33## Adding Tests 34Tests can be added by adding classes to the src directory. JUnit4 style test cases can 35be written by simply annotating test methods with `org.junit.Test`. 36 37## Debugging Tests 38If you are trying to debug why tests are not doing what you expected, you can add android log 39statements and use logcat to view them. The beginning and end of every tests is automatically logged 40with the tag `TestRunner`. 41 42## Code Coverage 43If you would like to collect code coverage information you can run the `coverage.sh` script located 44in this directory. It will rebuild parts of your tree with coverage enabled and then run the tests, 45similar to runtests.sh. If you have multiple devices connected to your machine make sure to set the 46`ANDROID_SERIAL` environment variable before running the script. You must supply an output directory 47for results. By default the results are generated as a set of HTML pages. For example, you can use 48the following from the root out your source tree to generate results in the wifi_coverage directory 49 50``` 51frameworks/opt/net/wifi/tests/wifitests/coverage.sh wifi_coverage 52``` 53