Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Looking for example how to utilize UnitTestingDefine

2021-06-03
7 days ago
  • pasi-p-sand

    pasi-p-sand - 2021-06-03

    Hello,

    I need to implement unit tests for a library and to do that efficiently I also need to have access to on-public POUs inside the library. Unit tests cannot be inside the library. I found this page from Online help (https://help.codesys.com/webapp/properties;product=LibDevSummary;version=3.5.17.0) which indicates that there is UnitTestingDefine definition that could be used for changing the visibility during compilation. Some more info in here (https://help.codesys.com/webapp/visibility;product=LibDevSummary;version=3.5.17.0) but I would like to see how it is used in practice.

    Thank you!

     

    Last edit: pasi-p-sand 2021-06-03
  • h-hermsen

    h-hermsen - 2021-06-03

    Unit tests cannot be inside the library.

    This statement is wrong since unit tests could be implemented into the same library that the production code resides in. I therefore assume this is a prerequisite or a customer wish?

     
  • pasi-p-sand

    pasi-p-sand - 7 days ago

    Hello,

    I've been busy with other stuff for a while but now this issue is again on the table.

    Yes, it is requirement from system architecture that unit tests are not implemented inside the library, so it is not doable for me. I also think that it is good practise since we want to keep the library 'clean'.

    Now back to my original problem. I want to call every FB and method defined in library-under-testing. I have defined another library (don't know whats the benefit of having a library instead of project) which contains only unit testing code. I have defined UNIT_TESTING in application properties (Build tab) of this library. I also have defined new UnitTestingDefine as "UNIT_TESTING" inside library-under-testing.

    Now the issue. Documentation says that defining UnitTestingDefine with a string (in this case UNIT_TESTING) should make compiler to ignore INTERNAL and PRIVATE keywords (among others). I have done that but still the unit testing library cannot see the FB in library-under-testing if it is defined with INTERNAL keyword. If the keyword is removed, build finishes without errors.
    Methods can have PRIVATE keyword and those are ignored with UnitTestingDefine.

    Have I misunderstood something? Should UnitTestingDefine be used some other way?

     

Log in to post a comment.