How to test a microflow that uses $currentUser in a XPath-constraint

0
We have a simple Microflow, that retrieves some Objects by using a XPath constraint like this: [MyApp.Receipt_User = $currentUser and year-from-dateTime(ReceiptDate) = $someDate] I wrote a Test-Microflow by using the Unittesting-Module to test the Query. When I executed the test I found out that $currentUser is empty, because the Testis executed as a system session. So I wrapped the call to the Microflow with CommunityCommons.executeMicroflowAsUser_1() to execute the microflow with user privileges. That works, but I dont’t know how to retrieve the result of the microflow under test. executeMicroflowAsUser returns a String instead of a list of entities and I want to add asserts based on this list. So I did some research in the forum and found this post: https://community.mendix.com/link/questions/82692 Is the solution provied in this post the right way to get the result of the microflow execution? What is the best practive approach when it comes to unittesting of microflows?   
asked
2 answers
1

There is no best practice for unit testing your specific use-case. The best shortcut is probably to copy CommunityCommons.executeMicroflowAsUser_1( ) and modify its Java code to make it return the objects.

answered
0

Alternatively, you could also add an input parameter to the microflow, an object of entity "System.User". In your regular calls, you can supply the microflow with the $currentUser as input parameter, whereas in your test microflow you first retrieve a user of choice and pass that to the retrieve microflow. 

However, if it's going to be a datasource microflow you will also need a wrapper microflow on your page(s), which is not optimal but that's the trade-off..

Alternatively, you could also add an input parameter to the microflow, an object of entity "System.User". In your regular calls, you can supply the microflow with the $currentUser as input parameter, whereas in your test microflow you first retrieve a user of choice and pass that to the retrieve microflow. 

However, if it's going to be a datasource microflow you will also need a wrapper microflow on your page(s), which is not optimal but that's the trade-off..

answered