You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "harmadasg (via GitHub)" <gi...@apache.org> on 2026/10/07 08:24:58 UTC

[PR] KAFKA-21237 - Remove accidental JUnit 4 usage [kafka]

harmadasg opened a new pull request, #23741:
URL: https://github.com/apache/kafka/pull/23741

   Currently [StreamsGroupDescribeRequestTest](https://github.com/apache/kafka/blob/85387e94364bdf31c6acf06086210d85a9fb0711/core/src/test/scala/unit/kafka/server/StreamsGroupDescribeRequestTest.scala#L32) includes accidental JUnit 4 assert usages. Based on my findings:
   
   - Historically [KAFKA-7339](https://issues.apache.org/jira/browse/KAFKA-7339) had the JUnit 4 to JUnit 5 in scope.
   - [KAFKA-19153](https://issues.apache.org/jira/browse/KAFKA-19153) pulled in a new dependency [Mock OAuth2 Server](https://mvnrepository.com/artifact/no.nav.security/mock-oauth2-server/2.3.0) which in turn depends on JUnit 4
   - [KAFKA-19754](https://issues.apache.org/jira/browse/KAFKA-19754) probably only used the JUnit 4 asserts by accident since the test library is on the test classpath
   
   As a fix I changed the asserts to the JUnit 5 equivalent and removed JUnit 4 from the test compile classpath so we can avoid similar accidents in the future.
   
   Other things I considered:
   
   - JUnit 4 can't be excluded from [Mock OAuth2 Server](https://mvnrepository.com/artifact/no.nav.security/mock-oauth2-server/2.3.0) as it is a runtime dependency which results in NoClassDefFoundError
   - Tried updating [Mock OAuth2 Server](https://mvnrepository.com/artifact/no.nav.security/mock-oauth2-server/2.3.0) to latest version but it still pulls in JUnit 4


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-21237 - Remove accidental JUnit 4 usage [kafka]

Posted by "harmadasg (via GitHub)" <gi...@apache.org>.
harmadasg commented on code in PR #23741:
URL: https://github.com/apache/kafka/pull/23741#discussion_r4224073139


##########
build.gradle:
##########
@@ -1245,6 +1245,9 @@ project(':core') {
       testRuntimeOnly.exclude module: 'api-ldap-schema-data'
       testCompileClasspath.exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
       testRuntimeClasspath.exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
+      // JUnit 4 is a transitive runtime dependency of mock-oauth2-server (via okhttp3 mockwebserver),
+      // keep it off the compile classpath so tests can't accidentally use JUnit 4 APIs.
+      testCompileClasspath.exclude group: 'junit', module: 'junit'

Review Comment:
   @chia7712 Thanks for the review! I have opened https://github.com/apache/kafka/pull/23752 based on your idea of using Keycloak for the eligible test cases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-21237 - Remove accidental JUnit 4 usage [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #23741:
URL: https://github.com/apache/kafka/pull/23741


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-21237 - Remove accidental JUnit 4 usage [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #23741:
URL: https://github.com/apache/kafka/pull/23741#discussion_r4210405292


##########
build.gradle:
##########
@@ -1245,6 +1245,9 @@ project(':core') {
       testRuntimeOnly.exclude module: 'api-ldap-schema-data'
       testCompileClasspath.exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
       testRuntimeClasspath.exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
+      // JUnit 4 is a transitive runtime dependency of mock-oauth2-server (via okhttp3 mockwebserver),
+      // keep it off the compile classpath so tests can't accidentally use JUnit 4 APIs.
+      testCompileClasspath.exclude group: 'junit', module: 'junit'

Review Comment:
   It seems mock-oauth2-server is only used by ClientOAuthIntegrationTest. As a follow-up, maybe we can refactor the client_credentials and client assertion cases to use Keycloak like ClientAssertionKeycloakIntegrationTest does.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org