Hi,
When creating unit tests for protocols, I can easily mock the protocol object to test the code & to assert if certain sets are executed from the code I'm testing. (using the Verify method)
I now started with my first unit test on an automation script, where I want to test several workflows.
In order to do so, I need to verify certain values coming from a linked element and also verify if sets are happening.
I was thinking on mocking (via MOQ nugget) the Element object, so I would be able to Setup values for Element.GetParameter, and introduce Verify on the SetParameter invocations.
I'm facing an issue where I can't assign the mocked object to an Element instance.
Can you please give me a hint how to overcome this problem?
Thanks!
This is because the Element returned from Engine or IEngine is a class and not an interface. When working with a class for mocking, it needs default constructors and even then not everything will always mock correctly.
I would recommend using the IDms and IDmsElement classes from the Class Library. Those interfaces can be easily mocked for unit testing. Any missing methods or features can be added to the class library as they are needed and requested.
Alternatively you can request a new software feature to provide and return interfaces for that library.
However that can have a serious impact (as we saw for Protocol, it took a lot of testing to address any impacted items).
That change would then also be linked to a Minimum DataMiner version.
Thanks guys! I was indeed able to proceed with mocking the IActionableElement interface. Do note that I also needed to change my script code itself to also make my element object of type “IActionableElement” instead of “Element”. (in order for the method to have the same input arguments)
Next time I’ll indeed consider to use the Class Library with IDms & IDmsElement classes.
Thanks again for the support!
Element implements the IActionableElement interface, it could be an option to look into creating your fakes based on this interface.