perlquestion
dragonchild
I'm looking to convert [cpan://DBM::Deep]'s test suite to use [cpan://Test::Class] because I need to reuse a large number of test cases. I really don't want to use a library of functions because that's going to get unwieldy very very quickly. So, I was hoping Test::Class would be the solution.
<p>The problem is that I have classes that have waaaay more functionality than can be tested in one file. So, the recommended organisation of Foo::Bar::Test testing Foo::Bar isn't going to work.
<p>What I'm thinking of is writing test classes that encapsulate tests given a certain setup. So, something like:
<code>
package Test::Floober;
# This inherits from Test::Class
use base 'My::Test::BaseClass';
sub test1 : Test(5) {
my $self = shift;
# Do stuff here with $self->{foo} and $self->{bar}
# that were passed in at new()
}
</code>
Then, in my test file, I could have something like:
<code>
use Test::Floober;
my $test = Test::Floober->new( foo => 2, bar => 5 );
my $test2 = Test::Floober->new( foo => 'abcd', bar => [ 2 .. 5 ] );
Test::Class->runtests( $test, $test2 );
</code>
I got a couple questions:
<ul>
<li>How does the plan get set in these instances? I <i>can</i> run planless, but I'd prefer not to.
<li>I'm not sure it will make sense in every instance to pre-build all the test cases as in the situation above. How would Test::Class know the plan then?
<li>Is this a sane use of Test::Class? My only exposure to xUnit has been Rails and the tests I wrote there were variations of the stock test, not anything complex.
</ul>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-85580">
<hr>
My criteria for good software:
<ol>
<li>Does it work?
<li>Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
</ol>
</div></div>