Skip to content

Commit 5f1bb66

Browse files
runningcodeclaude
andauthored
docs(agents): Prefer Google Truth for new unit test assertions (#5735)
Steer AI coding agents toward Google Truth's fluent assertThat API for assertions in new unit tests, while keeping kotlin.test for test structure. Truth is already a dependency in the sentry module; note that other modules need testImplementation(libs.google.truth) added before use. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 61ba1d5 commit 5f1bb66

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

.cursor/rules/coding.mdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentry-java is the Java and Android SDK for Sentry. This repository contains the
3131

3232
1. Follow existing code style and language
3333
2. Do not modify the API files (e.g. sentry.api) manually, instead run `./gradlew apiDump` to regenerate them
34-
3. Write comprehensive tests
34+
3. Write comprehensive tests. For assertions in new unit tests, prefer Google Truth (`com.google.common.truth.Truth.assertThat`) over `kotlin.test`/JUnit assertions; keep `kotlin.test` for test structure like `@Test` and `assertFailsWith`. Add `testImplementation(libs.google.truth)` to a module's `build.gradle.kts` if it isn't already present.
3535
4. New features should always be opt-in by default, extend `SentryOptions` or similar Option classes with getters and setters to enable/disable a new feature
3636
5. Consider backwards compatibility
3737

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ The repository is organized into multiple modules:
146146
- Write comprehensive unit tests for new features
147147
- Android modules require both unit tests and instrumented tests where applicable
148148
- System tests validate end-to-end functionality with sample applications
149+
- **Assertions**: For new unit tests, prefer [Google Truth](https://truth.dev/) (`com.google.common.truth.Truth.assertThat`) over `kotlin.test`/JUnit assertions for its readable, fluent API. Keep using `kotlin.test` for test structure (`@Test`, `assertFailsWith`). See `sentry/src/test/java/io/sentry/DsnTest.kt` for the style. Don't rewrite existing `kotlin.test` assertions solely to switch libraries.
150+
- Truth is wired into the `sentry` module. When adding Truth-based tests to another module, add `testImplementation(libs.google.truth)` to that module's `build.gradle.kts`.
149151

150152
### Contributing Guidelines
151153
1. Follow existing code style and language

0 commit comments

Comments
 (0)