[Mimedefang] MimeDefang Framework
Dave O'Neill
dmo at roaringpenguin.com
Tue May 29 17:32:18 EDT 2007
On Tue, May 29, 2007 at 05:04:33PM -0400, Jeff Rife wrote:
>
> That's all you need to do unit testing for your MD filter. The chunk
> you are testing stands alone...it does not need MIMEDefang to run.
>
Well... not quite true. Most filters will make calls against MIMEDefang
code, so testing your filter in a fully standalone environment will
require some test scaffolding. Otherwise, your tests will die with
errors like "Undefined subroutine &main::action_add_header called at..."
For example, if you have filter code that calls action_change_header(),
you would implement a stub for that method in your test script. It's
really not that hard to do, and from a unit-testing perspective it's
quite useful. For example, here's a simplified bit of code from one of
the CanIt-PRO unit tests:
sub can_add_header : Test(2)
{
my ($self) = @_;
my $header = [];
local *::main::action_change_header = sub { $header = [ $_[0], $_[1] ] };
ok( $self->{action}->execute( $self->{message}, $self->{stream}), '->execute returns OK');
cmp_deeply( $header, [ 'X-CanItPRO-Stream', $self->{stream}->get_stream_header() ], 'Got expected header added');
}
This test checks that execute() adds the correct header. To test this,
we have an action_change_header() that just saves its arguments, which
we then check after the call to execute().
(the :Test(2) stuff at the end of the sub line is because our unit
tests use the Test::Class framework. Highly recommended if you have a
complex testsuite)
Cheers,
Dave
--
Dave O'Neill <dmo at roaringpenguin.com> Roaring Penguin Software Inc.
+1 (613) 231-6599 http://www.roaringpenguin.com/
For CanIt technical support, please mail: support at roaringpenguin.com
More information about the MIMEDefang
mailing list