I am trying to test a batch flow but if I place a reference to a batch flow in my MUnit test, the test will finish instantly and run the asserts, while the batch flow continues in the background. Is there a way to force my batch job to run synchronously so that I can examine the results in my MUnit tests?
1
votes
If you have made your Code asynchronous then it can be helped when you call the parent flow as it will complete synchronously. If you need to test the Batch then make the batch to be in another flow and then call that flow which can help you finish the batch
– Naveen Raj
Yeah that's how it's set up currently. I also have the batch job setup to call subflows so I can test those subflows directly. I looked into the Synchronous component as well and that looks promising but not sure it's worth looking into further.
– CamJohnson26
Can you post your Flow.xml if possible . If not the actual flow atleast a mock flow that I can do a test on
– Naveen Raj
There's a lot of other stuff in my code, but just create a new project with a batch flow, throw "Set Payload" in the first step and the on complete step, and then try to build a test that will assert the final set payload. You'll see that you can't access the results of the batch job.
– CamJohnson26
1 Answers
2
votes
Here is an app showing how to do just that: https://www.mulesoft.com/exchange#!/munit-testing-batch-module
The way to achieve it is to use the following MUnit component: https://docs.mulesoft.com/munit/v/1.2.0/run-and-wait-scope
HTH