How to verify/check that an event not lead to the change? #1128
Replies: 1 comment
-
Greetings TH Koeln Alumni, long time no talk ;) In my opinion you should probably only test the successcase (the first case) in an integration test. If you want to test the internal decision making (the second case) you should resort to a classic unit test and exercise the eventhandler method or a subsequent "isAddressValid(...)" method in a synchronous way and just check for an InvalidAdressException or the expected non-result. No need to wait for a timeout in this case. An integration test is ment to test if the asynchronous communication between the tests actually works, not necessarily to test the internal funtionality of the receiving module - a unit test would be better suited here. Also if you really want to test the second case with the scenario API, there is a "andWaitAtMost(Duration duration)" method, which might work (haven't tested it) Best regards Marco Reitano |
Beta Was this translation helpful? Give feedback.
-
First of all, thank you very much for the great work.
I am currently integrating Spring Modulith into a brownfield project and have the following problem.
I use the ApplicationEvents to decouple the communication between two modules. I simply check that the events have been published with the
AssertablePublishedEvents
.When checking that the events have also been processed by the recipient, I now have two cases:
I tested/checked the first case as follows
The second case is much more difficult for me.
What I actually want to do is simply wait for the timeout to expire (without an error message!) and then verify that the shipping address is not changed to the event value. The problem with the method above is that
andWaitForStateChange()
already throws an error andandVerify()
is not called at all to confirm that this is the expected state...What am I doing wrong or how can I best test exactly this case?
Beta Was this translation helpful? Give feedback.
All reactions