This post celebrates the stable release of Carioca, a suite of testing libraries for Android that I’ve been working on since the last year.
This project is available here: https://github.com/rubensousa/Carioca
It contains 3 main component libraries:
- Instrumented test reports
- Hilt helper components
- Useful JUnit4 rules
In this post, I will briefly mention the set of libraries available. For more information about them, please check the website
Instrumented test reports
Analyzing the results of long-running UI tests can often feel like sifting through a haystack. The standard JUnit reports, while functional, can lack the context and visual aids needed to quickly pinpoint failures.
Remember that time you retried a pipeline just hoping the test was flaky and now this time will be green? Or remember that colleague that suggested ignoring some tests because they’re suddenly not passing, but everything seems fine? Say no more, we’ve all been there.
Carioca contains a thoughtful collection of APIs designed to enhance your testing workflow, with a strong emphasis on flexible and insightful reporting backed by Allure.
The instrumented test report library comes with these features:
- Take screenshots easily at any stage of a test
- Automatic video recordings of the test execution
- Generate an allure report for all tests
- Aggregate multi-module test results
- Automatic logcat attachment for every test failure
See this page for how to setup these reports.
After you integrate the library, an allure report is generated automatically with all relevant attached files:
This is done simply with a report rule and the allure reporting plugin:
This artifact contains the main library needed to start writing instrumented test reports:
androidTestImplementation("com.rubensousa.carioca:report-android:1.0.0")
And the Allure plugin is also available:
plugins {
id 'com.rubensousa.carioca.report.allure' version '1.0.0'
}
Hilt helper components
If you’re using Hilt in your application for dependency injection, you might find these useful for writing compose or fragment tests that need Hilt dependencies:
debugImplementation "com.rubensousa.carioca:hilt-manifest:1.0.0"
androidTestImplementation "com.rubensousa.carioca:hilt-fragment:1.0.0"
androidTestImplementation "com.rubensousa.carioca:hilt-compose:1.0.0"
androidTestImplementation "com.rubensousa.carioca:hilt-runner:1.0.0"
HiltFragmentScenario
: similar toFragmentScenario
but launches a Fragment inside an Activity that contains a Hilt entry pointcreateHiltComposeRule()
: similar tocreateAndroidComposeRule
but launches a composable inside an Activity that contains a Hilt entry pointHiltTestRunner
: a custom runner that launches an Application setup with a Hilt graph
Check the docs here for complete examples.
JUnit4 rules
Some of these I kept copying over multiple projects, so I just decided to make them available in a standalone library:
RetryTestRule
: retries tests until they pass or a certain limit is exceeded. This isn’t generally needed, unless you have full end-to-end tests that can fail due to unpredictable reasons.MainDispatcherRule
: replaces the main thread for unit tests, as seen hereRepeatTestRule
: similar toRetryTestRule
but fails the test immediately if a failure is caught. I’ve been using this to detect flakiness in tests, as I can easily execute a test 100s of times
These rules are available through the following:
testImplementation "com.rubensousa.carioca:junit4-rules:1.0.0"
androidTestImplementation "com.rubensousa.carioca:junit4-rules:1.0.0"
Get started
Explore the documentation and examples available in the official docs