adagnatgnat-gpsaunit

How can I specify functions or procedures GNATTest should auomatically generate a test case for


I'm working on a huge code package (written dominantly in ada), which is an extreme mess. No Unit Tests are applied so far and for all the existing code, Unit tests must not be implemented. But our Team decided, that all the new code should be implemented together with tests. Within GPS there is the possibility to let GNATtest automatically generate test procedures for all functions and procedures in the project. But as written, we have to exclude all of the old code from this automated genereation.

Is there a way to tag functions and procedures as "need to be tested"?


Solution

  • You can instruct gnattest to create tests only for selected procedures or functions by adding parameter --test-case-only. I'm not sure how to set it in GPS. Whole command in terminal can looks that:

    gnattest -P yourproject.gpr --test-case-only

    You can also add this parameter to your .gpr file:

        package GnatTest is
           for GnatTest_Switches use ("--test-case-only");
        end GnatTest;
    

    When you set it, you have to add aspect (or pragma) Test_Case. For example:

    procedure Something with
     Test_Case => ("Test_Something", Robustness);
    

    You can find more information about this aspect/pragma in GNAT Documentation. Link is to pragma definition, but aspect works exactly in that same way.