Skip to content

Fix the unit test check: MockWebServer tests need an Android to log to - #6922

Merged
AndyScherzinger merged 1 commit into
masterfrom
fix/noid/unit-tests-mockwebserver
Oct 17, 2026
Merged

AndyScherzinger merged 1 commit into
masterfrom
fix/noid/unit-tests-mockwebserver

Conversation

@AndyScherzinger

@AndyScherzinger AndyScherzinger commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

The test check has been red on every PR, for a reason that has nothing to do with the PRs failing it. Example: run 38948999876 — 1001 tests completed, 8 failed, all eight in NetworkLoginDataSourceTest.

What actually breaks

Every test that starts a MockWebServer dies before its first assertion:

java.lang.NoSuchMethodError: 'int android.util.Log.println(int, java.lang.String, java.lang.String)'
    at okhttp3.internal.platform.android.AndroidLog.androidLog$okhttp(AndroidLog.kt:92)
    at okhttp3.internal.concurrent.TaskLoggerKt.log(TaskLogger.kt:65)
    at okhttp3.mockwebserver.MockWebServer.start(MockWebServer.kt:155)

okhttp 5.5.0 routes its task logging through android.util.Log, which has no implementation in a plain JVM unit test.

Nothing in the app asked for okhttp 5. app/build.gradle.kts declares okhttpVersion = "4.12.0", but the version is lifted transitively:

com.squareup.okhttp3:okhttp-bom:5.5.0
\--- com.github.nextcloud.android-common:ui:0.34.0
     \--- project ':app'

The BOM is a platform, so it lifts the whole family at once — including the test-only artifact: com.squareup.okhttp3:mockwebserver:4.12.0 -> 5.5.0.

The fix

NetworkLoginDataSourceTest and AccountCookieInterceptorTest now run on Robolectric, which gives them a real android.util.Log. That is exactly what the MockWebServer tests that kept passing — ChunkedFileUploaderTest and ChunkedFileUploaderAbortTest — already do, so this makes the four consistent rather than introducing a new pattern. Only annotations and imports change; no assertion is touched.

I deliberately did not pin okhttp back to 4.12.0. The 5.5.0 comes from nextcloud-android-common, so pinning it here would fight an intentional upgrade and would be undone the next time that library moves.

Beyond the eight CI reported

AccountCookieInterceptorTest has the same defect and fails the same way when run on its own — six more tests. CI happened to pass it because Gradle shares one JVM across the suite and that class ran before the okhttp logging handler was installed, so its result depended on ordering. It is fixed here too rather than left as a latent flake.

I also checked the other three test classes that touch OkHttpClient without Robolectric — CapabilitiesFetcherTest, LocationPickerViewModelTest, WebSocketInstanceSignalingClientTest. They mock the client instead of making real calls, so they are unaffected and pass as they are.

Verification

./gradlew testGplayDebugUnitTest --rerun-tasks is green on this branch, the whole suite, no filters. ktlintCheck and detekt pass.

🖼️ Screenshots

No UI was added or changed — test-only.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed — this change is the test fix; the 14 affected tests pass and the rest of the suite is unchanged
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

okhttp 5.5.0 routes its task logging through android.util.Log, which has no
implementation in a plain JVM unit test. Every test that starts a MockWebServer
therefore died before its first assertion:

    java.lang.NoSuchMethodError: int android.util.Log.println(int, String, String)
        at okhttp3.internal.platform.android.AndroidLog.androidLog$okhttp
        at okhttp3.mockwebserver.MockWebServer.start

Nothing in the app asked for that version. The app declares okhttp 4.12.0, but
nextcloud-android-common:ui 0.34.0 brings okhttp-bom 5.5.0, and the platform
lifts the whole family with it - mockwebserver included.

Both classes now run on Robolectric, which gives them a real android.util.Log.
That is what the MockWebServer tests that kept passing, ChunkedFileUploaderTest
and its abort twin, already did. What the tests assert is unchanged.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@github-actions

Copy link
Copy Markdown
Contributor

📱 QA build

Download app-qa-debug.apk
QR code Open the QR code for this download
Commit 6a8e016
Version 6922
Available until 7 days after this build

The QA build installs alongside a released Nextcloud app, so you can keep
using your existing install while testing.

Downloading the file requires a GitHub account, so open this link on the
device you want to test on, or transfer the APK to it.

@AndyScherzinger AndyScherzinger added this to the 25.1.0 milestone Oct 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Codacy

Lint

TypemasterPR
Warnings138138
Errors1515

SpotBugs

CategoryBaseNew
Bad practice77
Correctness88
Dodgy code4040
Internationalization33
Malicious code vulnerability33
Performance88
Security1111
Total8080

@AndyScherzinger
AndyScherzinger merged commit 5126ab8 into master Oct 17, 2026
17 of 19 checks passed
@AndyScherzinger
AndyScherzinger deleted the fix/noid/unit-tests-mockwebserver branch October 17, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant