Munit test for choice router using parameterization

Ekta Sehgal
2 min readFeb 15, 2024

--

Parameterized choice router is used to avoid creating multiple MUnit test cases for each choice path.

Below is simple application with a choice router:

Depending on the color sent in payload by user, application will return response:

If color is Red, response is “color is Red”

If color is Green, response is “color is Green”

For any other color or no color, response is “No color”

Now we will create a blank test suite as below:

Now in order to define parameters , we have to go to munit_choice-test-suite.xml> Global elements > MUnit Configuration and define parameters for different routes as shown below:

Now click on “+” and add Parameterization name as “Red color route” and then define input and output as shown below, similarly do it for other routes.

setting input and output for different routes

After defining parameters, set payload in set event as highlighted below:

In assert equals, set expected payload as output from parameter as below:

Initiate Munit test and see all routes have been covered.

Note: Instead of defining parameters , we can also use yaml fine in MUnit configuration.

--

--

Ekta Sehgal
Ekta Sehgal

No responses yet