How To Use Test::Class

Ovid on 2009-03-13T08:22:39

My article on Test::Class has been published on modernperlbooks.com. It's broken down into bite-sized chunks as:

  1. Organizing Test Suites with Test::Class
  2. Reusing Test Code with Test::Class
  3. Making Your Testing Life Easier (refactoring and other tricks)

For German speakers, it's also due to be published in May (I think) in $foo Perl Magazin.

One note about the article: I first wrote that a few years ago and never got around to submitting it. Clearly, since the article uses Moose and Test::Most, I've updated it quite heavily. One update I forgot is that the Test:: namespace prefix should be clarified. It should be something like Tests:, My::Test: or Test::${company_name}:: or basically anything which avoids conflicts with the Test:: namespace.

So far comments have been nice and Piers Cawley mentions it in his blog and also seems quite happy with it (that's an awesome blog post, by the way. It's an attempt to bring Devel::Declare magic to Test::Class).

One thing which didn't survive chromatic's editing was my "Tip Summary" at the end of the three parts:

  • Name your test classes consistently after the classes they're testing.
  • When possible, do the same for your test methods.
  • Don't use a constructor test named new.
  • Create your own Test::Class base class.
  • Abstract the the name of the class you're testing into a class method in your base class (possibly the most important tip).
  • Name test control methods after their attribute.
  • Decide case-by-case whether to call a control method's parent method.
  • Don't put tests in your test control methods.

Some of those might sounds odd, but if you read the articles, I explain what's going on.


Thanks!

Asim on 2009-03-13T11:49:32

Your articles helped me sort out TDD w/Moose, an issue I had worked on a couple of weeks ago. Very timely, and effective.

Good article!

sigzero on 2009-03-13T12:43:00

Cleared up a bit for me.

Great Resource

jk2addict on 2009-03-13T13:12:31

I've been away from Perl for a while, so this is a great resource for me to get back into testing using Test::Class and not falling back to my old .t ways. :-)

Test::Able

zby on 2009-03-13T14:37:27

And reading comments under Pierses blog I found Test::Able - which boastes to be Moose based Test::Class.

Re:Test::Able

Ovid on 2009-03-13T15:33:50

Yeah, I was looking at that (saw in the same blog entry). Looks very cool and, because it uses a MOP, promises to make easy some things which are hard in Test::Class.