Fog Creek Software
Discussion Board

Perl and C# Unit Test Examples

I'm trying to find nice simple examples of Perl unit tests for testing some existing modules that I've deleoped and not written unit tests for yet, but I can't find any examples in the Test::Unit download that I can understand how it's decising what to test.

On another note, can anyone reccomend a good C# unit testing framework? I'm going to be learning that soon and would like to start out remembering to write my unit tests.

Friday, March 21, 2003

You can find an assortment of test suites here.

Friday, March 21, 2003

Forgot the link - sorry

Friday, March 21, 2003

Thanks for the link; I'm still confused about the Perl Test::Unit I've downloaded though. I'm just trying to do something like:

use eyeMaginationS::Utils;

my $emu = new eyeMaginationS::Utils;

# test 1
assert($emu->ISALWAYSTRUE == 0); # this test should fail.

Friday, March 21, 2003

For my C# unit tests I use Nunit:

Ian Stallings
Friday, March 21, 2003

If it's confusing you, you can always just do it yourself.

If you want to test a sub called resolve_contract_bids(), create a sub named test_resolve_contract_bids().  In the test sub: Set up test data, call resolve_contract_bids(), and test the test data to ensure that it's been processed correctly.  If it's wrong, return false; otherwise return true.

Then create a little script which calls test_resolve_contract_bids(), and prints "FAIL" if it returns false.

Add new calls to the script as you add new tests.

And you have an automated unit test suite.

Brent P. Newhall
Friday, March 21, 2003

Test::Unit work ok but it's far from the most used testing suite in Perl. Take a look at Test::More, which makes setting up and running tests a breeze. See chromatic's intro to testing [1], although keep in mind that it was written in Dec 2001 when you read comments about Test::More being new.


Chris Winters
Friday, March 21, 2003

*  Recent Topics

*  Fog Creek Home