misk
misk copied to clipboard
feat(misk-testing): add WebActionRegistrationTesting utility
Description
A common mistake when developing Misk services is implementing a WebAction but forgetting to register it via WebActionModule.create<YourAction>(). Without registration, the action won't be exposed as an HTTP endpoint, and this can be difficult to catch during development.
This PR adds WebActionRegistrationTesting to misk-testing - a utility that scans a service's packages for WebAction implementations and verifies each has a corresponding WebActionEntry registration. When missing registrations are detected, it fails with a helpful error message including copy-paste registration code.
What's included:
WebActionRegistrationTesting- core utility withassertAllWebActionsRegistered()AbstractWebActionRegistrationTest- JUnit base class for easy adoption- Documentation in
docs/actions.mdunder a new "Verifying action registration" section - ClassGraph dependency for classpath scanning
Example usage:
class WebActionRegistrationTest : AbstractWebActionRegistrationTest() {
override fun createInjector() = Guice.createInjector(MyServiceTestingModule())
override fun webActionPackages() = listOf("com.example.myservice")
}
Testing Strategy
- Added unit tests in
WebActionRegistrationTestingTest.ktcovering:- Passing when all actions are registered
- Failing with helpful message when actions are missing
- Excluding abstract classes automatically
- Respecting custom exclude predicates
- Including registration module hint in error messages
- Verified build passes with gradle :misk-testing:build
Communication Plan
- This is an additive, opt-in feature with no breaking changes
- Services can adopt it incrementally by adding a single test class
Checklist
- [ ] I have reviewed this PR with relevant experts and/or impacted teams.
- [x] I have added tests to have confidence my changes work as expected.
- [x] I have a rollout plan that minimizes risks and includes monitoring for potential issues.