When developing such components, you should get into the habit of writing integration tests in order to validate the component's behavior when your app runs on a device or an emulator.
Note: Android does not provide a separate test case class for
BroadcastReceiver. To verify that a
BroadcastReceiver responds correctly, you can test the component that sends
Intent object. Alternatively, you can create an instance of your
BroadcastReceiver by calling
ApplicationProvider.getApplicationContext(), then call the
BroadcastReceiver method that you want to test (usually, this is
This class teaches you to build automated integration tests using the testing APIs and tools that the Android platform provides.
- Test your service
- Learn how to build integration tests to verify that a service works correctly with your app.
- Test your content provider
- Learn how to build integration tests to verify that a content provider works correctly with your app.
To learn more about this topic, consult the following additional resources.