misk icon indicating copy to clipboard operation
misk copied to clipboard

feat(misk-testing): add WebActionRegistrationTesting utility

Open rnc505 opened this issue 3 weeks ago • 0 comments

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 with assertAllWebActionsRegistered()
  • AbstractWebActionRegistrationTest - JUnit base class for easy adoption
  • Documentation in docs/actions.md under 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.kt covering:
    • 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.

rnc505 avatar Dec 03 '25 21:12 rnc505