Skip to content

Add Kotlin unit test infrastructure and CircleCI step#159

Merged
jwilander merged 3 commits intomasterfrom
chore/add-kotlin-test-infrastructure
Mar 20, 2026
Merged

Add Kotlin unit test infrastructure and CircleCI step#159
jwilander merged 3 commits intomasterfrom
chore/add-kotlin-test-infrastructure

Conversation

@pavelzeman
Copy link
Copy Markdown
Contributor

Summary

Add infrastructure for running Kotlin unit tests in CI. Currently the repo has one Kotlin test file (ExponentialRetryInterceptorTest.kt) but no test dependencies in build.gradle and no CI step to run them.

The Android side of this library has 36 Kotlin files totaling ~3,250 lines of code — including interceptors for auth, retry, compression, timeouts, and metrics. That's a decent amount of logic with no test coverage in CI. This PR fixes that.

Ticket Link

N/A — infrastructure improvement to support ongoing Sentry issue fixes.

Release Note

NONE

Changes

  • android/build.gradle: Add testImplementation dependencies for JUnit 4, Mockito, and OkHttp MockWebServer
  • test-runner/: Standalone Gradle project with wrapper for running Kotlin unit tests independently of the React Native build. Includes a smoke test to verify the infrastructure works.
  • .circleci/config.yml: Add kotlin-tests job using cimg/android executor, wired as a gate for build-package

Why a standalone test-runner?

The Android module (android/build.gradle) is a library that depends on React Native at build time, making it difficult to run ./gradlew test standalone. The test-runner project provides a lightweight Kotlin+JVM environment with OkHttp dependencies — enough to test interceptor logic without the full React Native build chain.

What this enables

  • TDD for Android interceptor code (e.g. header validation, retry logic)
  • CI enforcement of Kotlin test correctness
  • Foundation for upcoming interceptor bug fixes (#155)

Migrated from #156 (fork → org branch)

pavelzeman and others added 3 commits March 20, 2026 00:36
Add JUnit 4, Mockito, and OkHttp MockWebServer as test dependencies.
These are needed to run the existing ExponentialRetryInterceptorTest and
future interceptor tests.

Co-authored-by: Claude <claude@anthropic.com>
- Add JUnit 4, Mockito, and OkHttp MockWebServer to android/build.gradle
  test dependencies
- Add standalone test-runner project with Gradle wrapper for running
  Kotlin unit tests independently of the React Native build
- Add kotlin-tests job to CircleCI using cimg/android executor
- Add smoke test to verify the test infrastructure works
- Wire kotlin-tests into the build workflow as a gate for build-package

This enables TDD for Android interceptor code without requiring a full
React Native app build.

Co-authored-by: Claude <claude@anthropic.com>
Address CodeRabbit review: prevent resource leaks if assertions fail
by using Kotlin's use{} for automatic cleanup of MockWebServer and
Response objects.

Co-authored-by: Claude <claude@anthropic.com>
@pavelzeman pavelzeman marked this pull request as ready for review March 20, 2026 13:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

The changes establish a new Kotlin test-runner module with complete Gradle build infrastructure, integrate unit test execution into the CircleCI CI/CD pipeline via a new kotlin-tests job, add unit test dependencies to the Android module, and introduce a basic smoke test validating OkHttp request/response functionality.

Changes

Cohort / File(s) Summary
CircleCI CI/CD Configuration
.circleci/config.yml
Added android executor using cimg/android:2024.01 image; introduced kotlin-tests job that runs Gradle unit tests and uploads JUnit/HTML reports; updated build workflow to require kotlin-tests before build-package.
Test-Runner Gradle Build Infrastructure
test-runner/build.gradle.kts, test-runner/settings.gradle.kts, test-runner/gradle/wrapper/gradle-wrapper.properties, test-runner/gradlew, test-runner/gradlew.bat
Added Gradle Kotlin DSL build configuration with Kotlin JVM plugin (1.9.22), mavenCentral() repository, and dependencies on okhttp and test libraries (junit, mockwebserver); configured Gradle wrapper (8.5) with shell and Windows batch launcher scripts; set root project name to "interceptor-tests".
Android Unit Test Dependencies
android/build.gradle
Added test dependencies: junit:junit:4.13.2, org.mockito:mockito-core:5.11.0, and com.squareup.okhttp3:mockwebserver:4.12.0.
Smoke Test
test-runner/src/test/kotlin/com/mattermost/networkclient/SmokeTest.kt
Added JUnit smoke test class validating end-to-end OkHttp request/response behaviour using MockWebServer; confirms HTTP 200 response code and body content "ok".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding Kotlin unit test infrastructure and integrating it into the CircleCI pipeline.
Description check ✅ Passed The description is comprehensive and clearly related to the changeset, detailing the motivation, changes, and rationale for the standalone test-runner approach.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/add-kotlin-test-infrastructure

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.

Add a configuration file to your project to customize how CodeRabbit runs biome.

Copy link
Copy Markdown
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

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

And... yet another bleed. I saw that you had the whole test-runner folder in a different PR. Not sure if that was intended or not.

Apart of that, LGTM.

@pavelzeman
Copy link
Copy Markdown
Contributor Author

And... yet another bleed. I saw that you had the whole test-runner folder in a different PR. Not sure if that was intended or not.

Apart of that, LGTM.

this only has test runner changes now

@pavelzeman
Copy link
Copy Markdown
Contributor Author

Once this is approved and merged, I'll rebase #160 (which has tests that rely on this PR to run in CI).

@jwilander - for some reason this repo still requires 2 reviewers, unlike other repositories.

@jwilander
Copy link
Copy Markdown
Member

We just updated that because CodeRabbit was causing auto-merges to happen before a human looked at it. Context here: https://hub.mattermost.com/private-core/pl/1rc98y1obbfjzbknr7bfdfnc8y

If CodeRabbit approves that will count as the second reviewer

@jwilander
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.circleci/config.yml (1)

69-83: Consider Gradle cache in kotlin-tests to reduce CI duration.

The new job will repeatedly download wrapper/dependencies; adding cache should speed up runs and reduce flaky network impact.

💡 Suggested CI cache snippet
   kotlin-tests:
     executor: android
     steps:
       - checkout
+      - restore_cache:
+          keys:
+            - gradle-test-runner-{{ checksum "test-runner/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "test-runner/build.gradle.kts" }}
+            - gradle-test-runner-
       - run:
           name: Run Kotlin unit tests
           command: |
             cd test-runner
             ./gradlew test
+      - save_cache:
+          key: gradle-test-runner-{{ checksum "test-runner/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "test-runner/build.gradle.kts" }}
+          paths:
+            - ~/.gradle/caches
+            - ~/.gradle/wrapper
       - store_test_results:
           path: test-runner/build/test-results
       - store_artifacts:
           path: test-runner/build/reports/tests
           destination: kotlin-test-reports
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.circleci/config.yml around lines 69 - 83, Add a Gradle cache for the
kotlin-tests job to avoid re-downloading the wrapper and dependencies: modify
the kotlin-tests job (job name "kotlin-tests", step running "./gradlew test" in
"test-runner") to add CircleCI cache restore/save steps for Gradle files (e.g.,
~/.gradle and the Gradle wrapper in test-runner/.gradle or
test-runner/.gradle/wrapper) using a key that includes the OS and gradle wrapper
checksum, restore the cache before running ./gradlew test and save it after the
build finishes so subsequent runs reuse downloaded dependencies and speed up CI.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.circleci/config.yml:
- Around line 69-83: Add a Gradle cache for the kotlin-tests job to avoid
re-downloading the wrapper and dependencies: modify the kotlin-tests job (job
name "kotlin-tests", step running "./gradlew test" in "test-runner") to add
CircleCI cache restore/save steps for Gradle files (e.g., ~/.gradle and the
Gradle wrapper in test-runner/.gradle or test-runner/.gradle/wrapper) using a
key that includes the OS and gradle wrapper checksum, restore the cache before
running ./gradlew test and save it after the build finishes so subsequent runs
reuse downloaded dependencies and speed up CI.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 427be98c-a605-43a7-8916-7e0f72ce10db

📥 Commits

Reviewing files that changed from the base of the PR and between dd42247 and 4291970.

⛔ Files ignored due to path filters (1)
  • test-runner/gradle/wrapper/gradle-wrapper.jar is excluded by !**/*.jar
📒 Files selected for processing (8)
  • .circleci/config.yml
  • android/build.gradle
  • test-runner/build.gradle.kts
  • test-runner/gradle/wrapper/gradle-wrapper.properties
  • test-runner/gradlew
  • test-runner/gradlew.bat
  • test-runner/settings.gradle.kts
  • test-runner/src/test/kotlin/com/mattermost/networkclient/SmokeTest.kt

@jwilander jwilander merged commit 1732edd into master Mar 20, 2026
1 check passed
@jwilander jwilander deleted the chore/add-kotlin-test-infrastructure branch March 20, 2026 20:39
@lieut-data
Copy link
Copy Markdown
Member

@pavelzeman & @larkox, do we even use CircleCI anymore?

@enahum
Copy link
Copy Markdown
Contributor

enahum commented Mar 23, 2026

@pavelzeman & @larkox, do we even use CircleCI anymore?

We dont't use it anymore, but we did when this repo was created although this repo never had it active and all the releases are done manually

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants