Skip to content

Conversation

@SaintPatrck
Copy link
Contributor

🎟️ Tracking

TBD

📔 Objective

Introduce a new Claude skill named testing-android-code to provide comprehensive guidance and standardized patterns for writing tests within the Bitwarden Android codebase.

The primary objective is to codify best practices and provide Claude with quick access to reference documentation, examples, and common pitfalls, thereby improving test quality, consistency, and development efficiency.

The skill is composed of the following documents:

  • A main SKILL.md file that serves as a quick-reference guide, outlining key patterns for testing ViewModels, Compose UIs, Repositories, and Services. It also introduces test data builders and utility classes.
  • A README.md explaining the purpose and contents of the skill.
  • Detailed reference documents for:
    • test-base-classes.md: Explains the usage of BaseViewModelTest, BitwardenComposeTest, and BaseServiceTest.
    • flow-testing-patterns.md: Details how to test StateFlow and EventFlow using Turbine, highlighting the critical differences in their testing patterns.
    • critical-gotchas.md: Lists common antipatterns and mistakes, such as misusing assertCoroutineThrows with runTest and forgetting to unmock static functions.
  • Complete, copy-pasteable examples for testing major components:
    • viewmodel-test-example.md
    • compose-screen-test-example.md
    • repository-test-example.md

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@github-actions github-actions bot added the t:ci Change Type - Updates to automated workflows label Jan 15, 2026
@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.77%. Comparing base (b0084d2) to head (43b52a6).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6370   +/-   ##
=======================================
  Coverage   85.77%   85.77%           
=======================================
  Files         775      775           
  Lines       56203    56203           
  Branches     8123     8123           
=======================================
  Hits        48207    48207           
  Misses       5172     5172           
  Partials     2824     2824           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 15, 2026

Logo
Checkmarx One – Scan Summary & Details9f8b0d12-6f8e-4359-8331-28c2e515f86d

Great job! No new security vulnerabilities introduced in this pull request

@SaintPatrck SaintPatrck force-pushed the claude/testing-android-code-skill branch 3 times, most recently from ebe7698 to f83fdfc Compare January 29, 2026 17:38
This commit introduces a new Claude skill named `testing-android-code` to provide comprehensive guidance and standardized patterns for writing tests within the Bitwarden Android codebase.

The primary objective is to codify best practices and provide developers with quick access to reference documentation, examples, and common pitfalls, thereby improving test quality, consistency, and development efficiency.

The skill is composed of the following documents:
- A main `SKILL.md` file that serves as a quick-reference guide, outlining key patterns for testing ViewModels, Compose UIs, Repositories, and Services. It also introduces test data builders and utility classes.
- A `README.md` explaining the purpose and contents of the skill.
- Detailed reference documents for:
    - `test-base-classes.md`: Explains the usage of `BaseViewModelTest`, `BitwardenComposeTest`, and `BaseServiceTest`.
    - `flow-testing-patterns.md`: Details how to test StateFlow and EventFlow using Turbine, highlighting the critical differences in their testing patterns.
    - `critical-gotchas.md`: Lists common antipatterns and mistakes, such as misusing `assertCoroutineThrows` with `runTest` and forgetting to unmock static functions.
- Complete, copy-pasteable examples for testing major components:
    - `viewmodel-test-example.md`
    - `compose-screen-test-example.md`
    - `repository-test-example.md`
@SaintPatrck SaintPatrck force-pushed the claude/testing-android-code-skill branch from f83fdfc to db99690 Compare January 29, 2026 17:49
@SaintPatrck SaintPatrck marked this pull request as ready for review January 29, 2026 17:50
@SaintPatrck SaintPatrck requested a review from a team as a code owner January 29, 2026 17:50
@SaintPatrck SaintPatrck requested review from a team and david-livefront January 29, 2026 17:51
@SaintPatrck SaintPatrck added the ai-review Request a Claude code review label Jan 29, 2026
@withinfocus
Copy link
Contributor

https://bitwarden.slack.com/archives/C09MHQNCSKD/p1769693094966979 -- is this a skill or a prompt? And do we think this will move to the marketplace in time or is so specific it will just be here? I am thinking about the reviewer agent benefitting.

@SaintPatrck
Copy link
Contributor Author

SaintPatrck commented Jan 29, 2026

@withinfocus it's a Skill, although I'm toying with the idea of making it a Rule once I've had a chance to tinker with them.

I keep going back-and-forth on moving it to the marketplace or keeping it here given it's so specialized. My main hesitation is the friction it may introduce for maintenance. If we consider it a living document to update as we fine-tune Claude for this repo, I would prefer it reside here. I feel like that will encourage and facilitate faster iterations.

The reviewer agent, and the implementor/developer agent being built, will inherently have access to this as long as they're initiated in the repo root. If we move it to the marketplace the plugin has to be manually installed everywhere. There may be ways to configure the repo to automagically install the marketplace+plugin, but I've not looked into that approach thoroughly.

For the sake of getting something started I think it's best we begin with it here, iterate a bit until the team is confident with it, then promote it to the marketplace if there's a larger desire/need to do so.

Edit:
With all of that being said, I just remembered we have at least one other Android repo. If it follows the guidelines and best practices we've established in this repo, that's a good enough reason for me to promote it to the marketplace sooner rather than later.

}

companion object {
private val DEFAULT_STATE = ExampleState(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this out of the companion object and just have it be at the top-level of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// Default state for assertions - always define complete expected states
private val defaultState = ExampleState(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stuff like this is usually top-level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..and done.

private fun createViewModel(
initialState: ExampleState? = null,
): ExampleViewModel = ExampleViewModel(
savedStateHandle = SavedStateHandle().apply { set("state", initialState) },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Moves the `DEFAULT_STATE` constant from a class-level property to a top-level private val in both `viewmodel-test-example.md` and `compose-screen-test-example.md`.

This change improves consistency and cleans up the test class structure by removing the `companion object` in the Compose test example.
@claude
Copy link
Contributor

claude bot commented Jan 29, 2026

Claude finished @SaintPatrck's task in 1m 40s —— View job


Code Review Complete

This PR introduces a comprehensive testing skill for Claude that codifies Bitwarden Android testing patterns. Overall, the documentation is well-structured and accurately reflects the codebase patterns.


Summary

The skill documentation provides excellent coverage of:

  • Base test class usage (BaseViewModelTest, BitwardenComposeTest, BaseServiceTest)
  • Turbine flow testing patterns (StateFlow vs EventFlow critical distinction)
  • Test data builders with the number: Int convention
  • Common gotchas and anti-patterns

The examples are thorough and demonstrate real-world testing scenarios.


Issues Found

1. Incorrect file path for assertCoroutineThrows (references/critical-gotchas.md, SKILL.md)

The documentation states the location as:

app/src/test/kotlin/com/x8bit/bitwarden/data/util/TestHelpers.kt

But the actual location is:

core/src/testFixtures/kotlin/com/bitwarden/core/data/util/TestHelpers.kt

This also affects the SKILL.md file at line 204 which lists this path.

Fix this →


Review Comments Already Addressed

The previous review comments have been addressed:

  • DEFAULT_STATE moved to top-level (out of companion object) per @david-livefront's feedback
  • ✅ KDoc comments in examples clarified as being for Claude context association, not production code style

Outstanding Review Comment

Regarding repository-test-example.md: @david-livefront asked about the assertSuccess pattern. Per the thread, this has been noted for removal since it's not a common pattern in the codebase.


Minor Suggestions

  1. BitwardenComposeTest managers list could be updated: The actual BitwardenComposeTest class has more managers than documented (e.g., CredentialProviderCompletionManager, CredentialExchangeImporter, QrCodeAnalyzer). Consider updating or noting this list is representative, not exhaustive.

  2. Reference files point to example paths: The test-base-classes.md references example paths like ../examples/viewmodel-test-example.md which is correct for relative navigation within the skill, but ensure these links work in the actual Claude skill rendering context.


Verification

I verified the following patterns against the actual codebase:

  • BaseViewModelTest location and stateEventFlow() helper signature matches
  • BitwardenComposeTest location and setContent() pattern matches
  • BaseServiceTest location and MockWebServer setup matches
  • assertCoroutineThrows is correctly documented as needing to be called without runTest wrapper
  • DEFAULT_STATE at file level (not companion object) matches existing test patterns
  • .asSuccess() and .asFailure() extension usage matches codebase

Recommendation

Approve with minor changes - The path for assertCoroutineThrows should be corrected before merging. The rest of the documentation is accurate and provides valuable guidance for writing tests in this codebase.


/**
* Test: Back button sends action to ViewModel
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally don't have docs on our tests, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is so Claude has examples of associating what is being tested to expected test names. Claude is not actually writing KDoc like this.


/**
* PATTERN: For error paths that require exceptions, create isolated
* repository instances with mocked dependencies.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It's coming from #6424. I'm going to remove it since we don't encounter this scenario often.

SaintPatrck and others added 3 commits January 29, 2026 21:26
- Compose tests: Change @beforeeach to @before (JUnit 4)
- Compose tests: Add dialog testing examples with isDialog()
- Repository tests: Fix Fake pattern to use private storage with setter
- Repository tests: Remove fictional emitData() helper method
- SKILL.md: Remove PR review references from pattern descriptions

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Rename "Reference Implementations" to "Complete Examples" and update
paths to point to the local example files instead of codebase files.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@SaintPatrck
Copy link
Contributor Author

These latest changes are looking good. #6442 was generated after the latest updates and correctly follows our testing guidelines for View Models. 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review t:ci Change Type - Updates to automated workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants