Hi, Malcolm,
Malcolm wrote:
how can I source out unit tests in a test library?
Usually, for this scenario, you have 3 projects:
- Testee - the library which contains the POU you want to test.
- Test Library - the library which contains the IEC unit tests (the POUs which define the test logic).
- Testbed - a project which contains the environment where the tests are to be executed, e. G. the correct device setup, task settings etc.
The "test library" needs to reference the "testee" library, and then the "testbed" project references the "test library".
I did attach a screenshot where you can see a testbed project which defines some of their own unit tests, as well as it references the CodeGeneratorTest library (newest version), and then the IEC Unit Test configuration which executes the unit tests from both the testbed project and the test library.
Attachment:
IecUnitTestInLibrary.png
For smaller projects and libraries, you don't need to source the unit tests out into their own test library - the compiler only compiles and downloads code which is actually referenced from the application, so as long as as you don't explicitly reference (create instances of and call) the test POUs within the application code, they are not part of the normal download, and thus can stay within the project or library without doing any harm.
Some Developers like to keep tests and code together, so they have all their unit test POUs within the library which defines the testees. If they want to lower user confusion, they can add hide their test POUs using:
Code:
{attribute 'hide'}
- see the online help chapter "Programming Reference > Declaration > Pragma Instructions > Attribute Pragmas > Attribute hide" for more information.
In some cases, you have the same testee and test library, but several different testbed projects - e. G. for our compiler tests, we have one testbed project for each target platform.
_________________
Check out the CODESYS store:
http://store.codesys.com/CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions