Skip to content

Conversation

@one-kash
Copy link

Summary

Migrate the android-test module from JUnit 5 to JUnit 4 to enable tests to run on Android API 21-25.

The JUnit 5 tests weren't running on older Android versions due to limitations of the android-junit5 plugin (requires API 26+).

Changes

Annotation migrations:

  • @BeforeEach@Before
  • @AfterEach@After
  • @Disabled@Ignore
  • @Tag → removed
  • @RegisterExtension → removed

Import changes:

  • org.junit.jupiter.api.*org.junit.*
  • TestAbortedExceptionAssumptionViolatedException

Build changes:

  • Removed de.mannodermaus.android-junit5 plugin
  • Simplified test instrumentation runner configuration
  • Use standard AndroidJUnitRunner

Test infrastructure:

  • Added @RunWith(AndroidJUnit4::class) to test classes
  • Manually manage MockWebServer lifecycle with @Before/@After
  • Simplified client creation without OkHttpClientTestRule

Test Plan

These tests should now run on all supported Android versions (API 21+).

Fixes #9134

JUnit 5 tests don't run on Android API 21-25 due to limitations of
the android-junit5 plugin. This change migrates the android-test module
to use JUnit 4 for broader device compatibility.

Changes:
- Replace JUnit 5 annotations with JUnit 4 equivalents
  - @beforeeach -> @before
  - @AfterEach -> @after
  - @disabled -> @ignore
  - @RegisterExtension -> removed (manual lifecycle management)
  - @tag -> removed (use @category if needed)
- Replace JUnit 5 assertions/assumptions with JUnit 4
- Replace TestAbortedException with AssumptionViolatedException
- Add @RunWith(AndroidJUnit4::class) to test classes
- Remove de.mannodermaus.android-junit5 plugin
- Update test instrumentation runner configuration
- Manually start/stop MockWebServer in test setup/teardown
- Simplify client creation without OkHttpClientTestRule

Fixes square#9134
/**
* Tests for SNI overriding on Android.
*/
@Tag("Remote")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove the tag?


junitPlatform {
filters {
excludeTags("Remote")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be removed.

@yschimke
Copy link
Collaborator

yschimke commented Jan 25, 2026

@one-kash are these AI generated? Just curious because of the regular PR structure, and some weird editing choices.

If so, one off. or some automated process suggesting PR fixes on public projects?

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.

Move all Android Unit Tests to Junit 4

2 participants