Professional Documents
Culture Documents
Test::DBIx::Class::Schema
Future
Finally
2011
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
In A Nutshell
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Why?
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Non-Lazy
# are specific columns defined? my $thingy = $model->resultset(BigBagOfFail); my @columns = qw/id name department/); can_ok($thingy, @columns);
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Non-Lazy
foreach my $column (@columns) { try { $thingy->$column(); ok("called $column()"); } catch($e) { diag $e; fail("$column() failed"); } }
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Non-Lazy
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Non-Lazy
Decide to test something new? How many .t les do you need to edit? More than zero? Too much work!!
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Getting Lazy
Test::DBIx::Class::Schema
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Test::DBIx::Class::Schema
My Attempt At Laziness
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
An example (setup)
my $schematest # required dsn => namespace => moniker => # optional username => password => });
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
An example (cong)
# tell it what to test $schematest->methods({ columns => [ qw( id name ) ], relations custom => [ qw( foo ) ], => [ qw( some_method ) ],
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
An example (running)
$schematest->run_tests();
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
You get. . .
can ok( @columns ) can ok( @relations ) can ok( @customs ) # row subs can ok( @resultsets ) # rs subs
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
$thing->$column called ok $thing->$relation called ok test that $column exists in the database ensure related-source exists test self.* and foreign.* columns for relationships test proxied relationships PASS/FAIL for relationship validity
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Functional Testing
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Benets
only maintaining a list (or three) lots of sanity checking nd out if someone deletes columns from the database upgrading TDCS improves *.t les for free
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Recommendations
Test one table/class per le Use Test::Aggregate Factor out ->new call for $schema
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
on the CPAN since 2008 used in production code since 2009 recent burst of improvements
never used to test empty tables - OOPS! used to be quite basic
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
Did It Work?
YES!
IMNSHO
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
What Next?
Wishlist relationship reciprocity relationships that are coderefs db columns that arent in the schema? tie-in with DBIx::Class::Schema::Loader
Net-A-Porter
Introduction
Test::DBIx::Class::Schema
Future
Finally
End Credits
QUESTIONS?
Me: chisel.wright@net-a-porter.com CPANID: CHISEL github: Module: metacpan.org/release/Test-DBIx-Class-Schema github.com/chiselwright/test-dbix-class-schema github.com/chiselwright
Net-A-Porter