#52 Unit tests in separate CODESYS-project

None
closed
nobody
None
2021-07-16
2021-06-03
pasi-p-sand
No

I have implemented unit tests code-to-test.library. Unit testing code is written into code-to-test_UnitTests.project. I found that it is only possible to call public POUs from the library. Is there a way around this limitation?

I found that there is possibility to define UnitTestingDefine in Codesys application which would cause PRIVATE, INTERNAL, PROTECTED and FINAL keywords to be ignored during UnitTest application compilation. Is there an example how to utilize this feature?

Discussion

  • hermsen

    hermsen - 2021-06-03

    I found that it is only possible to call public POUs from the library. Is there a way around this limitation?

    Without alteration in the library it is not possible. Since the library is open source you may do so at your own discretion.

    I found that there is possibility to define UnitTestingDefine in Codesys application which would cause PRIVATE, INTERNAL, PROTECTED and FINAL keywords to be ignored during UnitTest application compilation. Is there an example how to utilize this feature

    See below

     
  • hermsen

    hermsen - 2021-06-03

    UnitTestingDefine usage

    1) Add the UnitTestingDefine := 'someRandomName' to your library properties

    3) Next, right click your application to edit properties, go to build tab, and type someRandomName into the compiler defines

     
  • pasi-p-sand - 2021-06-03

    Thanks for quick response.

    I'm having trouble...
    This is what I have in unit test project application properties build tab:

    And library properties:

    I tested how it works and I got error message saying the FB with INTERNAL keyword is not found (Unknown type). If I remove the INTERNAL keyword and recompile then the error message is gone.

    Which version of Codesys is this feature first introduced?

     
  • pasi-p-sand - 2021-06-03

    Some testing results:
    Codesys V3.5 SP 14 Patch 2: UnitTestingDefine doesn't work with INTERNAL FB nor PRIVATE methods
    Codesys V3.5 SP 16 Patch 3: UnitTestingDefine doesn't work with INTERNAL FB but works with PRIVATE methods

     
  • hermsen

    hermsen - 2021-06-03

    As far as I know the access specifier INTERNAL has been introduced at least since SP10 (so usage may be valid even before SP10) and can be used with;

    • Function block
    • Property (Get, Set)
    • Method

    It will cause that Access to the function block is limited to the namespace (the library).

    See: https://help.codesys.com/webapp/_cds_f_obj_pou;product=codesys;version=3.5.10.0

    A tip: focus on "hiding" the contents (i.e. applying access specifiers) in parts of your library in a proper manner after you have solved all your other programming work/needs. This way, wrongly applied specifiers will not hinder your normal day to day development.

    You could always ask on the general forum for tips and tricks on how to approach this, since the question is a general programming question and not specifically coUnit related.

     
  • hermsen

    hermsen - 2021-07-16

    Ticket moved from /prj/cfunit/questions/17/

     
  • hermsen

    hermsen - 2021-07-16
    • status: --> closed
    • Milestone: --> None
     

Log in to post a comment.