Unfunctional unit testing - “the main thing is to shine”. Part 2

    Last year I wrote a short note about non-functional testing - i.e. about tests trying to detect an ugly and complicated code to maintain. Of course, such tests do not guarantee the perfect code, but they will provide some minimum level of quality. despite the obviousness of the requirements of these tests, many ignore them and then have to understand the procedures for 5,000 lines.
    The note in LJ did not cause the expected feedback (I would like to know what I missed), therefore, despite the resistance of the Habr, I decided to post a sequel here (thanks to the people who added karma).
    The following changes have occurred since the publication of the first note:
    - added a test for cyclomatic complexity and the number of lines of a code block (04_complexity.t), for cyclomatic complexity set a maximum of 20 (some offer 30, but each one corrects it - see the increase in the probability of an erroneous fix see here ), set the maximum number of lines in a block at random - 50, edit by yourself, but remember - if the block has nested branches and needs to be scrolled on the screen, then this is already ineffective.
    - added a test for the presence of use warnings (05_warnings.t)
    - the warings in 08-code-coverage.t only appear on FreeBSD on me, on Ubuntu the test worked fine, but I had to reduce the amount of coverage
    - I got the result on github
    git clone git@github.com:worldmind/perl-test-code-quality-template.git

    What do we know if did all tests succeed?
    We know that:
    - the code compiles without errors
    - strict pragmas are included
    - there are no FIXME marks left
    - Perl :: Critic believes that our code corresponds to Perl Best Practice
    - the cyclomatic complexity and the number of lines of the function (or code outside the function) do not exceed threshold values
    - the code has POD, it is valid and covers all the functions
    - a certain percentage of code covered by tests
    - the distribution meets the formal requirements CPAN


    ought to check more maximum nesting conditions (5) and cycle (2), and perhaps even some code metrics , but the finished module until Mr. I walked, maybe you need to write.

    upd. there is already a patch from cub.uanicI’ll look tomorrow - sort of useful

    Also popular now: