Home / Companies / StackHawk / Blog / Post Details
Content Deep Dive

GRPC Cleanup Extension for JUnit 5

Blog post from StackHawk

Post Details
Company
Date Published
Author
Topher Lamey
Word Count
595
Language
English
Hacker News Points
-
Summary

The grpc-java project offers GrpcCleanupRule for cleaning up Grpc Service resources in JUnit 4 tests, but it is incompatible with JUnit 5, which utilizes extensions instead of the @Rule classes used in JUnit 4. Despite the GRPC team's recommendation to continue using JUnit 4, StackHawk has developed a JUnit 5 extension named GrpcCleanupExtension to automatically manage resource cleanup and prevent test pollution. This extension, which mirrors the functionality of GrpcCleanupRule, tracks and shuts down server and channel resources after each test execution via the afterEach function. By implementing this extension, StackHawk ensures that resources are properly terminated, thereby maintaining test reliability and cleanliness.