I have been a big fan of coded workflows since their addition. I like to use them because it allows me to have very neat and organized automations. However, I am still looking for guidelines on doing testing with them.
Studio - Registering custom services At this link, UiPath provides instructions on how to register and use services between workflows. Anyone have any good examples for registering/mocking services for unit testing?
In a normal .NET application, you can pass services in through the constructor of a class when testing. But the service container in coded workflows work differently than this.
I understand how to register services in the CodedWorkflow partial class, but there is not any guidance on how to handle mocking these services when writing test cases.
Hi! I also like coded workflows for keeping automations organized. For testing, I usually mock services by creating simple stub implementations that return expected data, which lets me test workflows without calling real services. UiPath’s Studio instructions are helpful, but creating small test doubles often makes unit testing easier.
I think what I am going to do is make a separate mock implementation of my service’s interface. Then, in my CodedWorkflow partial class where the services are registered, I check if there is an environmental variable “USE_MOCKS”.
That way, in my test workflow arrange section, I can set that environment variable that tells it to register the mocked services rather than the real ones. This way, I can properly unit test the coded workflows