Closed zip-hashan closed 2 years ago
Hi @zip-hashan
Is there a specific testing challenge you're trying to overcome? All command/notification handlers are POJOs, so you can easily test them with your favorite unit testing and mocking library.
Hi @sizovs, I am using MockK with JUnit and AssertJ on a Spring boot application. So, wondering how to mock and test Pipelinr handlers when using @MockK
and @InjectMockKs
annotations? 🤔
@zip-hashan Just create an instance of Handler and provide mocked dependencies via constructor:
@Test
fun showsHowToTestHandlersWithMockk() {
val dep1 = mockk<Dependency1>()
val dep2 = mockk<Dependency2>()
val handler = YourCommandHandler(dep1, dep2)
var command = YourCommand()
val result = handler.handle(command)
assertNotNull(result)
}
In most of the unit testing/mocking libraries, you can also create mocks by annotating dependencies in your test. How to use MockK or other specific testing libraries is out of this project's scope. The best place is MockK documentation.
Hi There,
Could you please include how to unit test the functionality in Kotlin/Java and Spring boot?
Cheers 🙂