Howto

kevin

For whom is it?

Customers who have purchased Automation Platform and who develop their own plug-ins for the CODESYS development system.

What is it?

Automation Platform uses its own proprietary implementation for dependency injection, and it turns out to be rather hard to develop unit tests for plug-ins which require external dependencies.
Therefore the APUnitTestFramework is a software component which mimics the CODESYS environment during the runtime of a unit test, and which enables resetting the environment to its initial state (which is not a feature in the real Automation Platform at all, for various reasons).

How to build it?

You must adapt the references in the solution and the csproj files to your individual installation of the Automation Platform SDK, as well as the postbuild step. After that, building and installing the APUnitTestFramework.plugin.dll should be no problem for experienced Automation Platform developers.

How to use it?

  • Instantiate the Testbed class (preferably in a using-statement, as it requires disposal at the end of the test).
  • If you require entire plug-ins as dependencies for your testee plug-in, use the IncludeAdditionalPlugInGuid method (not recommended at all, as it contradicts the sense of a unit test).
  • If you require mocks for dependencies for your testee plug-in, use the AddMock methods. The parameters are mainly the TypeGuid to be mocked, and a factory method to create the mock instance on demand. Take care of the boolean systemInstance parameter as well.
  • Initialize the testbed. This is the same as starting up a CODESYS instance with the specified dependencies. You do not need to prepare any version profiles; this is done automagically by the APUnitTestFramework.
  • Do your tests.
  • Dispose the testbed (if not used in a using-statement).

Notes

  • APUnitTestFramework only works for dependencies which are declared using our own Dependency Injection mechanisms. For older plug-ins which are using the legacy ComponentManager calls, this framework will not be useful at all.
  • If your tests fail due to unresolved references, you can attach to the Testbed's DependencyError event to find out details.
  • We do not actively support this framework as a product. It works in-house in a couple of ways, so we are fine with the current state. If it does not work for you (remember: many Automation Platform customers have quite customized environments), then we cannot help. Feel free to dive into the code by yourself; there's a lot to learn about the internal workings of the Automation Platform.

Start a new Talk topic