Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Print summary of tests results when using Test::More ?

by perl4life (Initiate)
on Sep 10, 2017 at 20:49 UTC ( #1199046=perlquestion: print w/replies, xml ) Need Help??

perl4life has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I'm using Test::More to write tests for my application.

There are a lot of tests, so when it's complete I'd like to give the user a summary like all tests passed, or 5 tests failed 25 passed, etc.

I'm not seeing anyway to do this within the module however, does anyone know a way to do this?

thanks!

  • Comment on Print summary of tests results when using Test::More ?

Replies are listed 'Best First'.
Re: Print summary of tests results when using Test::More ?
by choroba (Archbishop) on Sep 10, 2017 at 20:54 UTC
    Do you use prove to run the tests?

    I see the following at the end of its output:

    Test Summary Report ------------------- t/05-functions.t (Wstat: 256 Tests: 5 Failed: 1) Failed test: 4 Non-zero exit status: 1 Files=10, Tests=446, 1 wallclock secs ( 0.06 usr 0.01 sys + 0.46 cu +sr 0.06 csys = 0.59 CPU) Result: FAIL
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Print summary of tests results when using Test::More ?
by 1nickt (Abbot) on Sep 10, 2017 at 20:56 UTC

    Hi, Are you using prove?

    Example:

    vagrant@vagrant:/as > prove -lr t/0* t/000-config.t ........ ok t/001-pod-coverage.t .. ok t/040-crypt.t ......... ok t/050-types.t ......... ok All tests successful. Files=4, Tests=67, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.99 cusr + 0.10 csys = 1.12 CPU) Result: PASS
    See also perldoc prove.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Print summary of tests results when using Test::More ?
by haukex (Bishop) on Sep 10, 2017 at 21:25 UTC
    I'm not seeing anyway to do this within the module

    choroba and 1nickt already pointed you to prove, which I think is the best answer, but just to answer this part of the question, yes, there are ways to get at the test results from within the test script itself, although that isn't really how the test architecture works - test scripts generate TAP output which is then consumed by harnesses to generate the statistics etc. across multiple test files.

    If tests in an individual script fail, you already get an output like "# Looks like you failed 5 tests of 30." at the end of the test script. To get at this information yourself, Test::More->builder->details returns a list of hashes that you can inspect yourself (see Test::Builder):

    my ($passed,$failed) = (0,0); my @tests = Test::More->builder->details; for my $test (@tests) { if ($test->{ok}) {$passed++} else {$failed++}; } diag "Of ".(0+@tests)." tests, $passed passed and $failed failed.";

    Now AFAIK and as far as I can tell from looking at the source, what prove does is use TAP::Harness, which in turn uses TAP::Parser and TAP::Formatter::Base to generate the summary output. But again, it's much easier to just use prove.

      thank you all for the replies!

      no I had no idea about prove, I do now see there's one small mention of it in 'other components' in the test::more doc.

      prove is exactly what i needed thank you again.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1199046]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2020-09-26 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (141 votes). Check out past polls.

    Notices?