Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

heusserm (4461)

  (email not shown publicly)
AOL IM: MatthewHeusser (Add Buddy, Send Message)

Matt Heusser is JAPH and an XP-Er []. (The Methodology, not the Operating System.) Right now, he's doing a lot of Test Driven Development in Perl.

Journal of heusserm (4461)

Thursday December 04, 2003
11:35 AM

Generic Unit Tests

[ #16165 ]

Someone on JoelonSoftware wanted to figure out how to do automated unit tests in TCL, so I wrote up this post:

Mike Scwern wrote test::More for Perl as well as test::Tutorial.

Basically, I'd suggest making a simple library with functions like this:

sub tests(int);
sub eq(string, int, int);
sub eq(string, bool, bool);
sub eq(string, double, double);
sub eq(string, string, string);
sub ok(string, bool);

The psuedo code looks something like this:

GLOBAL iTestNum int;
sub tests(i int)
    printf("1..%d\n", i);
    iTestNum = 1;

sub ok(s string, b bool)
    if (b)
        print("ok %d - %s\n", iTestNum, s);
        print("not ok %d - %s\n", iTestNum, s);

sub eq(s string, i int, i2 int)
    if (i==i2)
        print("ok %d - %s\n", iTestNum, s);
        print("not ok %d - %s\nGot %d\nExpected %d\n",
                        iTestNum, s, i, i2);
} //---End Psuedo Code

So your output to STDIO looks like this:

ok 1 - Foo with valid input
ok 2 - Foo with invalid group number
ok 3 - Error Message for invalid group number
not ok 4 - Foo with invalid date
not ok 5 - Error Message for invalid date
    Expected - "Date 10/35/2003 is not a valid date"
    Got - ""

Obviously, your function is something like:

func foo(iGroupNum int, sDate string) returns BOOL;

--All this is pseduo code you can write up in any langauge.

If you write it correctly, you can pump it through Test::Harness or Prove automatically.

That's the 5 minute version, anyway. You can write test harnesses in any language. (If you die after test 3 because of an unhandled exception, you know you SHOULD have had 5 tests because of the 1..5, so that too is a test.)

Thoughts? I think there's some interesting potential stuff about a "Generic Unit Test Framework", but it needs more work ...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Cross-language testing is one of my explicit goals. As long as that format matches the spec, there shouldn't be any reason prove can't be run on it.


    • Re:Yay! (Score:2, Informative)

      This is yet another of these "But it's already there!" comments. I checked and found TclTkUnit,
      /* */