Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

テストデータどうしてますか?

3,760 views

Published on

Kansai.pm #14で発表した、「テストデータどうしてますか?」という資料です。

Published in: Business
  • Dating direct: ♥♥♥ http://bit.ly/36cXjBY ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❤❤❤ http://bit.ly/36cXjBY ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

テストデータどうしてますか?

  1. 1. id:shiba_yu362011/11/26 Kansai.pm #14
  2. 2. • • shiba_yu36@hatena • @shiba_yu36 • shibayu36@github• •
  3. 3. # fixture.yml- name: entry1 data: id: 1 title: my policy- name: entry2 data: id: 2 title: please join
  4. 4. use Test::More;use Test::Fixture::DBI;construct_fixture( dbh => $dbh, fixture => /path/to/fixture.yaml,);
  5. 5. use Test::More;my $data = DBIx::Sample->create( id => 1, title => entry1,);my $data2 = DBIx::Sample->create( id => 2, title => entry2,);# add test ...
  6. 6. sub create_sample (;%) { my %args = @_; unless (defined $args{id}) { $args{id} = int(rand(1000000)); } my $sample = DBIx::Sample->create(id => $args{id}); unless ($args{title}) { $args{title} = String::Random->new->randregex([a-z]{40}); } $sample->title($args{title}); return $sample;}
  7. 7. use Test::More;my $data = create_sample;my $data2 = create_sample(title =>entry1);# add test ...
  8. 8. CREATE TABLE `sample` ( id int(10) unsigned NOT NULL, title varchar(20) NOT NULL, body text);
  9. 9. my $factory_maker = DBIx::DataFactory->new({ username => root, password => , dsn => dbi:mysql:dbname=sample,});
  10. 10. $factory_maker->create_factory_method( method => create_sample, table => sample, auto_inserted_columns => { id => { type => Int, size => 10, }, title => { type => Str, size => 20, }, },);
  11. 11. my $values = $factory_maker->create_sample;warn $values->{id};# +-----------+----------------------+------+# | id | title | body |# +-----------+----------------------+------+# | 452882908 | E54521Hpjkp9Wv1i9Rkb | NULL |# +-----------+----------------------+------+
  12. 12. my $values = $factory_maker->create_sample( title => title, body => body,);# +------------+-------+------+# | id | title | body |# +------------+-------+------+# | 3931487566 | title | body |# +------------+-------+------+
  13. 13. $factory_maker->create_factory_method( method => create_sample, table => sample, auto_inserted_columns => { id => sub { int rand(1000000000) }, title => { type => Str, size => 20, }, },);

×