From 2d0500aa74e422850710e89a2d55aa7c0ae0760e Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Tue, 7 Jul 2026 14:28:32 +0200 Subject: [PATCH] docs(agents): Prefer Google Truth for new unit test assertions 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 --- .cursor/rules/coding.mdc | 2 +- AGENTS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.cursor/rules/coding.mdc b/.cursor/rules/coding.mdc index 4e6fd2538a..fbcda27b12 100644 --- a/.cursor/rules/coding.mdc +++ b/.cursor/rules/coding.mdc @@ -31,7 +31,7 @@ sentry-java is the Java and Android SDK for Sentry. This repository contains the 1. Follow existing code style and language 2. Do not modify the API files (e.g. sentry.api) manually, instead run `./gradlew apiDump` to regenerate them -3. Write comprehensive tests +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. 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 5. Consider backwards compatibility diff --git a/AGENTS.md b/AGENTS.md index a05d938660..ec2ef62974 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -146,6 +146,8 @@ The repository is organized into multiple modules: - Write comprehensive unit tests for new features - Android modules require both unit tests and instrumented tests where applicable - System tests validate end-to-end functionality with sample applications +- **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. +- 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`. ### Contributing Guidelines 1. Follow existing code style and language