Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

is perl testing the answer?

by bobdeath (Scribe)
on Jun 03, 2003 at 16:20 UTC ( [id://262699]=perlquestion: print w/replies, xml ) Need Help??

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

The topic I would like to bring up involves testing in perl. The question I ask is, "Are the perl testing modules all that is needed in way of unit testing?". I am not just talking about unit testing perl modules either, but for any language such as C/C++ library testing, and Java class testing, etc. I was wondering if various Inline modules could be used to provide an interface to these different languages, and if so would it be a good idea to leave all unit testing up to perl?

Replies are listed 'Best First'.
Re: is perl testing the answer?
by chromatic (Archbishop) on Jun 03, 2003 at 16:40 UTC

    I'd rather use the Perl testing libraries than any other testing library I've used, but I wrote part of them so they fit my brain. There's been some talk about using Inline::C and some glue to write tests for exported perl functions in Perl (XS-level testing), but no one's ever done it to my knowledge.

    That said, if you want to do good unit testing in another language, your tests have to be accessible to the developers. If they know Perl and Perl testing well, that's fine. If they only know Java, say, you're probably better off with jUnit.

Re: is perl testing the answer?
by Juerd (Abbot) on Jun 03, 2003 at 16:43 UTC

    I think Perl is great for testing RPC api's, but Perl is not very usable for testing strong typed languages. It can be used to test the results of functions that have side effects, though (for example: if some function should create a file and write a certain string to it, Perl probably provides one of the easiest ways to check if its contents are correct).

    That said, I don't think it'll be hard to output "1 ok\n" in other languages, so why bother with Perl?

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      That said, I don't think it'll be hard to output "1 ok\n" in other languages, so why bother with Perl?

      Obviously you've never tried to print a string to stdout in Java!

      -sam

      That said, I don't think it'll be hard to output "1 ok\n" in other languages, so why bother with Perl?

      indeed. at a previous assignment, i wrote a testing library for korn shell scripts, in korn shell. i wrote my tests first, and produced over three thousand lines of the highest quality ksh i've ever written.

      that said, i'm glad i'm back to programming perl. the ability to write expressive tests makes expressive programming safe and easy.

      ~Particle *accelerates*

Re: is perl testing the answer?
by thelenm (Vicar) on Jun 03, 2003 at 19:20 UTC

    I use the Test::Harness module all the time in testing my C++ code. All it took was to write an extremely minimal C++ class to emulate the behavior of Test::More, then put appropriate targets in a Makefile to do the following things when I type make test:

    • Compile the C++ tests into executables, linking against my Test::More emulation class.
    • Create a one-liner Perl program for each executable that simply runs the executable and spits its output to STDOUT (because Test::Harness expects to be running Perl programs). Something like
      #!/usr/bin/perl print `./foo.t`;
      where foo.t is the C++ test executable.
    • Run the one-liners using Test::Harness, like this:
      perl -e 'use Test::Harness qw(&runtests $$verbose); $$verbose=${VERBOS +E}; runtests @ARGV;' ${TEST_SCRIPTS} 2>/dev/null
      where ${VERBOSE} is either 1 or 0 and ${TEST_SCRIPTS} is the list of Perl one-liners.

    Whether this is the best or easiest approach, I'm not sure. I came up with it on my own after much searching for freely-available unit testing code in C++. But if anyone can suggest such code, or a better way to go about testing C++ using the Perl Test:: modules, I would love your input.

    -- Mike

    --
    just,my${.02}

      Whether this is the best or easiest approach, I'm not sure. I came up with it on my own after much searching for freely-available unit testing code in C++. But if anyone can suggest such code, or a better way to go about testing C++ using the Perl Test:: modules, I would love your input.

      If you want a C++ xUnit framework you might be interested in taking a look at CxxTest, unit++, CppUnitLite or CppUnit.

      While I've not used it myself I've heard good things about CppUnitLite.

      (not that there is anything wrong with using Perl ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found