#17 Unit tests in separate CODESYS-project

None
2021-06-03
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?

Answers

  • h-hermsen

    h-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

     

    Last edit: h-hermsen 2021-06-03
  • h-hermsen

    h-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

     

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

    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?

     

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

    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

     

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

      h-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.

       

Log in to post a comment.