in reply to Testing Template, or should I write a diff for TT templates?

The fact that it uses a templating engine is merely a distraction. What you actually have is a system that outputs certain text.

Consider it a black box. For some given set of inputs, it should produce an acceptable output text.

What defines that acceptability? That's what you test. If you use a regex-based engine or a literal match, that's up to you. If someone checks in a template that fails that test, then you either fix the template or fix the test.

For example, you could have as one of your acceptance standards that it forms valid XML. So part of your test, you parse the XML. If it fails, that's not acceptable.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re: Testing Template, or should I write a diff for TT templates?

Replies are listed 'Best First'.
Re: •Re: Testing Template, or should I write a diff for TT templates?
by EvdB (Deacon) on Nov 14, 2003 at 18:21 UTC
    Do you mean something like this:
    Template: blah blah [% user.name %] blah, blah. Test data: $$vars{user}{name} = "<<<<<< user.name >>>>>>" Template produces: blah blah <<<<<< user.name >>>>>> blah, blah. Testing code: ok( $output =~ m/<<<<<< user.name >>>>>>/ );
    However this method could easily lead to very involved tests for complicated pages - and testing the test code could become trickier than testing the template.

    Also if I have understood you correctly it will make it difficult to test real world data. As I see it the only really good way to test the templates is to create simplified ones and then to check the output against known good results - even if that is more labour intensive.

    --tidiness is the memory loss of environmental mnemonics