http://www.perlmonks.org?node_id=470261

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

I've just started to dive into Catalyst and I have to say I'm loving it. It makes the easy things easy, provides the right framework to work in, and has been the impetus for me to really start learning TT and CDBI. One of best things is that Catalyst creates the initial test scaffolding for you, broken down by functional area. So, you have your application tests, and then the tests for each of the MVC components in their own subdirectory of t/. It even comes with its own Apache::Test-like infrastructure, so you can test without needing Apache or mod_perl installed. However, I'm not sure what I should be testing.

With the controllers, I'm pretty comfortable with the idea of mocking up the appropriate model and view classes so that I know what I'm testing. So, that's not a big issue.

With respect to CDBI, Catalyst uses Class::DBI::Loader to auto-generate the CDBI classes for you, based on your schema. My CDBI classes literally look like:

package MyApp::M::CDBI::MyTable; use strict; 1; __END__
I've looked at Automated testing of database classes, but then I realized that since I'm not modifying the classes, any additional tests I write beyond the use_ok()-type tests will be testing CDBI::Loader, and so they shouldn't be in my application's test suite. So, should I write any tests here? I'm comfortable without any, but am I missing something?

With respect to TT, I've got a lot of .tt files that get PROCESS'ed into my templates, where appropriate. I also have a lot of BLOCKs, WRAPPERs, and the like. Catalyst provides a MyApp::V::TT, but that's the place where Catalyst ends and TT begins. I've got my TT configuration options and some every-page values (like my menubar), but I'm not testing any of the actual TT code. Ideally, I'd like testing the actual TT snippets, but I'm at a loss for where to begin. An additional facet is that a lot of these snippets are probably going to be used in other projects, so I'd ideally like for them to have their own test suites ... ?

Basically, I'm literally asking for wisdom here. Catalyst, CDBI, and TT are all amazing infrastructures, but they're very daunting and I'm at a loss for where to begin when it comes to a test suite.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re: Testing TT and CDBI under Catalyst
by Corion (Patriarch) on Jun 27, 2005 at 13:44 UTC

    If you have any non-trivial SQL in your cdbi classes, I would test that against a predefined database (SQLite makes creating test databases easy). Any invariants of your non-stock constructors or set_sql queries fall under that.

    I don't know what framework you already have for verifying/testing your created HTML, but I would go with something like Test::WWW::Mechanize or Test::HTML::Content (which really lacks functionality I admit) to see that the correct output gets created. This testing of the templates is more an end-to-end test though and not a test of the single snippets, but maybe you can create some stripped-down templates that leave out all the "uninteresting" fluff. Indeed, supplying an alternative configuration/template directory might be enough already for your different tests.

Re: Testing TT and CDBI under Catalyst
by sri (Vicar) on Jun 28, 2005 at 01:47 UTC
      That does a system test. I'm looking to do component (or subsystem) tests.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        Thats an area where we still need to establish some best practices.
        I just access the components directly from the generated unit tests and use Test::MockObject to generate a fake context.