On Sat, 26 Jan 2002 00:23:40 -0500
"Perrin Harkins" <[EMAIL PROTECTED]> wrote:

> But what about the actual data?  In order to test my $product->name()
> method, I need to know what the product name is in the database.  That's
> the hard part: writing the big test data script to run every time you
> want to run a test (and probably losing whatever data you had in that
> database at the time).
> 
> This has been by far the biggest obstacle for me in testing, and from
> Gunther's post it sounds like I'm not alone.  If you have any ideas
> about how to make this less painful, I'd be eager to hear them.

You're not alone ;) here is my solution.

* All datasource are maintained with separate config file
* Generate config file for testing
* Create database and tables for testing (called test_foo)
* Insert dummy data into test_foo
* Test 'em
* Drop dummy data

Then my test script has both client side testing and server side
testing, like this.

  use Test::More 'no_plan';

  BEGIN { do 'db_setup.pl'; }
  END   { do 'db_teardown.pl'; }

  # server-side
  my $product = Product->create({ name => 'foo' });

  # client-side
  my $ua = LWP::UserAgent->new;
  my $res = $ua->request(GET "/foo/bar");
  like $res->content, qr/foo/;

  my $form = HTML::Form->parse($res->content);
  my $req2 = $form->click;
  my $res2 = $ua->request($req);
  like $res2->content, qr/blah/;

  # server-side
  my @p = Product->retrieve_all;
  is @p, 2;




--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

Reply via email to