SlideShare a Scribd company logo
1 of 36
id:shiba_yu36

2011/11/26 Kansai.pm #14
•
    • shiba_yu36@hatena
    • @shiba_yu36
    • shibayu36@github
•
    •
# fixture.yml
- name: entry1
  data:
    id: 1
    title: my policy
- name: entry2
  data:
    id: 2
    title: please join
use Test::More;
use Test::Fixture::DBI;

construct_fixture(
    dbh => $dbh,
    fixture => '/path/to/fixture.yaml',
);
use Test::More;

my $data = DBIx::Sample->create(
    id    => 1,
    title => 'entry1',
);
my $data2 = DBIx::Sample->create(
    id    => 2,
    title => 'entry2',
);

# add test ...
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;
}
use Test::More;

my $data = create_sample;
my $data2 = create_sample(title =>
'entry1');

# add test ...
CREATE TABLE `sample` (
   id int(10) unsigned NOT NULL,
   title varchar(20) NOT NULL,
   body text
);
my $factory_maker = DBIx::DataFactory->new({
    username => 'root',
    password => '',
    dsn      => 'dbi:mysql:dbname=sample',
});
$factory_maker->create_factory_method(
    method   => 'create_sample',
    table    => 'sample',
    auto_inserted_columns => {
        id => {
            type => 'Int',
            size => 10,
        },
        title => {
            type => 'Str',
            size => 20,
        },
    },
);
my $values = $factory_maker->create_sample;
warn $values->{id};
# +-----------+----------------------+------+
# | id        | title                | body |
# +-----------+----------------------+------+
# | 452882908 | E54521Hpjkp9Wv1i9Rkb | NULL |
# +-----------+----------------------+------+
my $values = $factory_maker->create_sample(
    title => 'title',
    body => 'body',
);
# +------------+-------+------+
# | id         | title | body |
# +------------+-------+------+
# | 3931487566 | title | body |
# +------------+-------+------+
$factory_maker->create_factory_method(
    method   => 'create_sample',
    table    => 'sample',
    auto_inserted_columns => {
        id => sub { int rand(1000000000) },
        title => {
            type => 'Str',
            size => 20,
        },
    },
);
テストデータどうしてますか?
テストデータどうしてますか?
テストデータどうしてますか?

More Related Content

What's hot

Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
Webmontag Berlin
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
Remy Sharp
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
pugpe
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 

What's hot (20)

Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"Webmontag Berlin "coffee script"
Webmontag Berlin "coffee script"
 
Database performance 101
Database performance 101Database performance 101
Database performance 101
 
Database api
Database apiDatabase api
Database api
 
PHP performance 101: so you need to use a database
PHP performance 101: so you need to use a databasePHP performance 101: so you need to use a database
PHP performance 101: so you need to use a database
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHPDifference between mysql_fetch_array and mysql_fetch_assoc in PHP
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
6. CodeIgniter copy2
6. CodeIgniter copy26. CodeIgniter copy2
6. CodeIgniter copy2
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 

Viewers also liked

Trinity Conversation Questions
Trinity Conversation QuestionsTrinity Conversation Questions
Trinity Conversation Questions
profecolaborador
 
Useful phrases for work and everyday life
Useful phrases for work and everyday lifeUseful phrases for work and everyday life
Useful phrases for work and everyday life
raja1910
 
More level-1-students-book
More level-1-students-bookMore level-1-students-book
More level-1-students-book
trung vu
 

Viewers also liked (15)

Visual Studioでテストデータを作ろう
Visual Studioでテストデータを作ろうVisual Studioでテストデータを作ろう
Visual Studioでテストデータを作ろう
 
Blog entry1
Blog entry1Blog entry1
Blog entry1
 
Demand-Driven Context-Sensitive Alias Analysis for Java
Demand-Driven Context-Sensitive Alias Analysis for JavaDemand-Driven Context-Sensitive Alias Analysis for Java
Demand-Driven Context-Sensitive Alias Analysis for Java
 
Cambridge speaking & listening exam entry 1 phase 1a
Cambridge speaking & listening exam entry 1 phase 1aCambridge speaking & listening exam entry 1 phase 1a
Cambridge speaking & listening exam entry 1 phase 1a
 
ご注文は監視自動化ですか?
ご注文は監視自動化ですか?ご注文は監視自動化ですか?
ご注文は監視自動化ですか?
 
Trinity Conversation Questions
Trinity Conversation QuestionsTrinity Conversation Questions
Trinity Conversation Questions
 
Tom's TEFL - Time And Daily Routine
Tom's TEFL - Time And Daily RoutineTom's TEFL - Time And Daily Routine
Tom's TEFL - Time And Daily Routine
 
English for everyday activities
English for everyday activitiesEnglish for everyday activities
English for everyday activities
 
Useful phrases for work and everyday life
Useful phrases for work and everyday lifeUseful phrases for work and everyday life
Useful phrases for work and everyday life
 
Speaking English (Linking Words)
Speaking English  (Linking Words)Speaking English  (Linking Words)
Speaking English (Linking Words)
 
English book 1 teacher
English book 1 teacherEnglish book 1 teacher
English book 1 teacher
 
Modern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesModern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial Databases
 
PPT ON ENGLISH
PPT ON ENGLISHPPT ON ENGLISH
PPT ON ENGLISH
 
More level-1-students-book
More level-1-students-bookMore level-1-students-book
More level-1-students-book
 
データベース設計徹底指南
データベース設計徹底指南データベース設計徹底指南
データベース設計徹底指南
 

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

第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource
Kaz Watanabe
 

Similar to テストデータどうしてますか? (20)

DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
Drupal7 dbtng
Drupal7  dbtngDrupal7  dbtng
Drupal7 dbtng
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Drupal 8 database api
Drupal 8 database apiDrupal 8 database api
Drupal 8 database api
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
php2.pptx
php2.pptxphp2.pptx
php2.pptx
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
PHP webboard
PHP webboardPHP webboard
PHP webboard
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
Smarty
SmartySmarty
Smarty
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource
 

More from Yuki Shibazaki

130427 kansai-emacs-github
130427 kansai-emacs-github130427 kansai-emacs-github
130427 kansai-emacs-github
Yuki Shibazaki
 
Cinnamon - simple deploy tool
Cinnamon - simple deploy toolCinnamon - simple deploy tool
Cinnamon - simple deploy tool
Yuki Shibazaki
 
120225perl入学式02自己紹介
120225perl入学式02自己紹介120225perl入学式02自己紹介
120225perl入学式02自己紹介
Yuki Shibazaki
 
没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成
没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成
没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成
Yuki Shibazaki
 

More from Yuki Shibazaki (10)

131026 kansai-emacs
131026 kansai-emacs131026 kansai-emacs
131026 kansai-emacs
 
130713 kyotopm-lt
130713 kyotopm-lt130713 kyotopm-lt
130713 kyotopm-lt
 
130427 kansai-emacs-github
130427 kansai-emacs-github130427 kansai-emacs-github
130427 kansai-emacs-github
 
130412 kayac-cinnamon
130412 kayac-cinnamon130412 kayac-cinnamon
130412 kayac-cinnamon
 
Cinnamon - simple deploy tool
Cinnamon - simple deploy toolCinnamon - simple deploy tool
Cinnamon - simple deploy tool
 
130207 kyotorb
130207 kyotorb130207 kyotorb
130207 kyotorb
 
121221社内lt
121221社内lt121221社内lt
121221社内lt
 
120225perl入学式02自己紹介
120225perl入学式02自己紹介120225perl入学式02自己紹介
120225perl入学式02自己紹介
 
120225perl入学式02
120225perl入学式02120225perl入学式02
120225perl入学式02
 
没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成
没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成
没入コミュニケーションに利用する3次元仮想キャラクタの半自動生成
 

Recently uploaded

Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
amitlee9823
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
daisycvs
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Anamikakaur10
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
dlhescort
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
Abortion pills in Kuwait Cytotec pills in Kuwait
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
lizamodels9
 

Recently uploaded (20)

Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 

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

  • 2.
  • 3. • shiba_yu36@hatena • @shiba_yu36 • shibayu36@github • •
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. # fixture.yml - name: entry1 data: id: 1 title: my policy - name: entry2 data: id: 2 title: please join
  • 11. use Test::More; use Test::Fixture::DBI; construct_fixture( dbh => $dbh, fixture => '/path/to/fixture.yaml', );
  • 12.
  • 13.
  • 14.
  • 15. use Test::More; my $data = DBIx::Sample->create( id => 1, title => 'entry1', ); my $data2 = DBIx::Sample->create( id => 2, title => 'entry2', ); # add test ...
  • 16.
  • 17.
  • 18.
  • 19. 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; }
  • 20. use Test::More; my $data = create_sample; my $data2 = create_sample(title => 'entry1'); # add test ...
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. CREATE TABLE `sample` ( id int(10) unsigned NOT NULL, title varchar(20) NOT NULL, body text );
  • 27. my $factory_maker = DBIx::DataFactory->new({ username => 'root', password => '', dsn => 'dbi:mysql:dbname=sample', });
  • 28. $factory_maker->create_factory_method( method => 'create_sample', table => 'sample', auto_inserted_columns => { id => { type => 'Int', size => 10, }, title => { type => 'Str', size => 20, }, }, );
  • 29. my $values = $factory_maker->create_sample; warn $values->{id}; # +-----------+----------------------+------+ # | id | title | body | # +-----------+----------------------+------+ # | 452882908 | E54521Hpjkp9Wv1i9Rkb | NULL | # +-----------+----------------------+------+
  • 30. my $values = $factory_maker->create_sample( title => 'title', body => 'body', ); # +------------+-------+------+ # | id | title | body | # +------------+-------+------+ # | 3931487566 | title | body | # +------------+-------+------+
  • 31.
  • 32.
  • 33. $factory_maker->create_factory_method( method => 'create_sample', table => 'sample', auto_inserted_columns => { id => sub { int rand(1000000000) }, title => { type => 'Str', size => 20, }, }, );

Editor's Notes

  1. テストデータどうしてますか?というタイトルで発表します、shiba_yu36です\n
  2. まずは自己紹介から\n
  3. 柴崎優季\nhatena, twitter, github\nはてなエンジニアバイト\n
  4. perlとかjavascriptをよく使います\n
  5. perlで作ったものとして\nbit.lyのapiラッパーであるWebService::Bitly、CSRFを自動的に防ぐMojoliciousプラグイン、あとは今回後で紹介するDBIx::DataFactory\n最近はCPANに上げる前にレビューをしてもらえるPrePANとかも手伝ってます\n
  6. では本題です\n
  7. \n
  8. 色々方法はあると思う\nFixtureを使う、ORMとかを直接使ってデータを入れる、テストデータを生成するためのユーティリティ関数を用意してそれを使うなどの方法が考えられます\n1つずつ考えていきますね\n
  9. \n
  10. たとえばymlファイルにこんな感じでデータを書いておいて、\n
  11. テストスクリプト内で読み込んでやると、テスト用のデータが生成されます\n
  12. データと実際のテストが分離していて読みづらいことがある\n\n
  13. もうfixtureとか使わずに直接テストスクリプト内でデータを入れたらいいんじゃないかって思いました\n
  14. 次の方法なんですが、直接データを入れる方法についてです\n
  15. DBIx::SampleをなんらかのORMとかとすると、こんな感じでcreateする\nこうしておくことでテストとデータの関係が見やすくなる\n
  16. 結局さっき言ってた追加したデータでテストが落ちる\ncolumnが10個くらいあったらやばい、ちょっとしたテストを書きたいだけでも長くなる\n
  17. \n
  18. というわけで次の方法ですが、テストデータ生成用のユーティリティメソッドを作る方法です\n
  19. 例えばこんな感じです。idとtitleのみのデータを入れることができるtableがあったとして、こういうふうにしておくと、データが指定してあればそれを入れる、そうでなければidに整数値をランダムで入れたり、titleに文字列をランダムで入れたりするようなメソッドができます。\n
  20. 使い方はこんな感じですね。上の例だとランダムでデータが入るし、下だとtitleには指定したデータが入ります\nこうすれば、毎回書くの面倒じゃなくなるし、ランダムで入れる分データの競合も少なくなる、ちょっとしたテストを書きたいときでも手軽に書ける\n
  21. \n
  22. \n
  23. \n
  24. DBIx::DataFactoryというモジュールです\n
  25. DBIx::DataFactoryというモジュールです\n
  26. このようなschemaがあるとします。\nidが10桁の整数で、titleが20文字、bodyはtextです。\n
  27. それでこのtableにデータを入れるためのメソッドをDBIx::DataFactoryを使って実装するとこのようになります\nインスタンスをdsnなど指定して作ります\n
  28. method名、table名、自動的に生成したいcolumnを指定してメソッドを作成します。\n自動的に生成したいcolumnはデフォルトにあるtypeを指定してどんなデータを入れるか決めます\n今回だったらidにIntタイプで10桁、titleにStrタイプで20桁を指定しています\n
  29. 作成したメソッドの使い方はこんな感じです。何も指定しないと、自動で生成する設定にしたcolumnに値が入ります。insertしたvaluesが帰ってきます\n
  30. データを指定すると、指定したカラムには指定されたデータが、そうでないところには自動で生成するデータが入ります\n
  31. 自動生成データとしてデフォルトで指定できるtypeは今のところ4種類です\nまた、プラガブルにしているので、自分でTypeを作成することも出来ます\n
  32. もっと柔軟にデータを作れるように、coderefで作れるようにもしています。\n
  33. こんな感じ\n
  34. \n
  35. YAPC::Asiaに行ったらモジュールが出来てたので、行くといいですね\n
  36. \n