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.

Perl web app 테스트전략

2,690 views

Published on

Korean Perl Workshop 2012 에서 발표한 Perl Web App Test 전략

Published in: Technology
  • Be the first to comment

Perl web app 테스트전략

  1. 1. https://metacpan.org/source/JJNAPIORK/Catalyst-Runtime-5.90016/t
  2. 2. https://metacpan.org/source/JJNAPIORK/Catalyst-Runtime-5.90016/t/ dead_recursive_chained_attributes.t
  3. 3. TestAnythingProtocol
  4. 4. cpantesters.org
  5. 5. 26,171Number of CPAN Distributions on CPAN 2012. 10. 19
  6. 6. 23,816,487Number of CPAN Testers Reports 2012. 10. 19
  7. 7. Test::MockObject Test::Class Test::Git Test::DeepTest::FITesque Test::TCP Test::mysqld Test::.... Test::YAML
  8. 8. Test::MostTest::MoreTest::Simple
  9. 9. Test::Simpleok( <expression>, <description> );
  10. 10. Test::Simple#!/usr/bin/env perluse strict;use warnings;use Test::Simple tests => 3;sub is_number_two {returnshift == 2;}my$var = JEEN is married to Hanny-Mama;ok(1+1 == 2, 1+1 = 2);ok($var =~ /married/, JEEN is married);ok(is_number_two(2), is_number(2) returns true?);
  11. 11. Test::Moreok( <expression>, <description> );is( <got>, <expected>, <description>);isnt( <got>, <expected>, <description>);like( <got>, <expected>, <description>);unlike( <got>, <expected>, <description>);isa_ok( <got>, <expected> );is_deeply( <HASH>, <HASH>, <description> );SKIP: {}TODO: {}
  12. 12. Test::More#!/usr/bin/env perl use strict; use warnings; use Test::Base tests => 4; my$var = JEEN is married; my%hash1 = (is_solo => 1,gender => male);my%hash2 = (is_solo => 1,gender => male,);ok(1+1 == 2, 1+1 = 2);is(1+1, 2, 1+1 = 2);like($var, qr/married/, JEEN is married);is_deeply(%hash1, %hash2, equal hashes);
  13. 13. TAP::Formatter::HTML
  14. 14. #!/usr/bin/env perluse strict;use warnings;use utf8;use Test::More tests => 2;BEGIN{binmodeSTDOUT, :utf8;};subtest 001) 의존모듈 확인 => sub { use_ok LWP::UserAgent; use_ok URI; use_ok URI::QueryParam;};my$host = $ENV{TARGET_HOST} || http://test-domain-blah-blah;my$ua = LWP::UserAgent->new();$ua->timeout(10);subtest 002) XSS => sub {while(<DATA>) {s/[rn]//g;my$uri = URI->new($host . $_);my@query_param = $uri->query_param;my$param_count = scalar@query_param;formy$idx (1 .. $param_count) {$uri->query_form({$uri->query_form,$query_param[$idx-1] => "<script>alert(xss);</script>" });my$res_xss = $ua->get($uri); unlike($res_xss->decoded_content, qr{<script>alert(xss );</script>}); } }};done_testing();__DATA__..................
  15. 15. t/ 001-xss.t 002-sql-injection.t 003-directory-indexing.t 004-filedownload.t 005-path-location.t 006-os-command.t ... ... ...
  16. 16. $ prove -v tt/001-xss.t ..1..2ok 1 - 001) 모듈 의존성 확인 ok 1 LWP::UserAgent ok 2 URI ok 3 URI::QueryParamok 2 - 002) XSS ok .... ok .... ok .......All tests successful.Files=xx, Tests=xxx, x wallclock secs ( 0.xx usr 0.xx sys + 0.xx cusr 0.xx csys = x.xx CPU)Result: PASS
  17. 17. use strict;use warnings;use utf8;use Test::More;use Catalyst::Test MySocial::App;use HTTP::Request::Common;use JSON::XS;use MySocial::App;my$reply = "악플은 최소한입니다.";my$photo = MySocial::App->path_to(root, static, images, profile, pict22.jpg);my$res = request( POST "/rate/1/comment","X-Social-Token" => "f9a077fae03cf63bc4b351344531bde91f0f26c9","Content_Type" => "form-data",Content => [reply => $reply,photo => [ $photo->stringify, $photo->stringify, "Content-Type" => "image/jpg" ], ]);my$data = JSON::XS::decode_json($res->content);ok($data->{success}, "리퀘스트 성공");ok($data->{comment}, "코멘트가 있습니다.");ok($data->{comment}->{id}, "코멘트 ID 가 제대로 존재합니다.");ok($data->{comment}->{reply}eq$reply, "코멘트 내용이 입력한 값과 동일합니다.");ok($data->{comment}->{user}, "코멘트 입력자가 존재합니다.");done_testing();
  18. 18. └── t ├── 00100_controller_User.t ├── 00400_controller_Scrap.t ├── 00101_controller_User_signup.t ├── 00401_controller_Scrap_add_category.t ├── 00102_controller_User_signin-out.t ├── 00402_controller_Scrap_get_categories.t ├── 00103_controller_User_get_user.t ├── 00403_controller_Scrap_delete_category.t ├── 00104_controller_User_friend.t ├── 00404_controller_Scrap_add.t ├── 00105_controller_User_get_friends.t ├── 00405_controller_Scrap_get_scraps.t ├── 00106_controller_User_unfriend.t ├── 00406_controller_Scrap_delete_scrap.t ├── 00107_controller_User_update_info.t ├── 00500_controller_Rate.t ├── 00108_controller_User_suggested_users.t ├── 00501_controller_Rate_add.t ├── 00109_controller_User_get_users.t ├── 00502_controller_Rate_get_rate.t ├── 00110_controller_User_update_devicetoken.t ├── 00503_controller_Rate_get_rates.t ├── 00200_controller_Ask.t ├── 00504_controller_Rate_comment.t ├── 00201_controller_Ask_add.t ├── 00505_controller_Rate_get_comments.t ├── 00202_controller_Ask_get_ask.t ├── 00506_controller_Rate_delete_comment.t ├── 00203_controller_Ask_get_asks.t ├── 00506_controller_Rate_delete_comment.t.html ├── 00204_controller_Ask_comment.t ├── 00600_controller_Notification.t ├── 00205_controller_Ask_get_comments.t ├── 00601_controller_Notification_add.t ├── 00206_controller_Ask_delete_comment.t ├── 00602_controller_Notification_get_notifications.t ├── 00300_controller_Venue.t ├── model_API.t ├── 00301_controller_Venue_add.t └── view_JSON.t ├── 00302_controller_Venue_get_venue.t ├── 00303_controller_Venue_get_venues.t ├── 00304_controller_Venue_report.t ├── 00305_controller_Venue_get_photos.t ├── 00306_controller_Venue_get_photo.t
  19. 19. use strict;use warnings;use Test::More tests => 4;use Test::WWW::Mechanize;my $id = your_naver_id;my $passwd = your_naver_password;my $reply = Check! :);chomp($reply);my $url = http://nid.naver.com/nidlogin.login;my $mech = WWW::Mechanize->new();$mech->get_ok($url, ‘로그인페이지에 접속’);my $res = $mech->submit_form_ok({ form_name => frmNIDLogin, fields => { id => $id, pw => $passwd },}, ‘폼 서브밋성공’);my $base_url = http://cafe.naver.com/AttendanceView.nhn;my $check_urls = "$base_url?search.clubid=18062050&search.menuid=6";$mech->get_ok($check_url, ‘카페에 접속’);$mech->field(content, $reply);$mech->submit();$mech->content_like(qr/$reply/, ‘댓글 등록확인’);
  20. 20. schema.sqlCREATE TABLE ...CREATE TABLE ...... DBIx::Class::Fixtures DBIx::Class::Migrationdata.sql / jsonINSERT INTO ...INSERT INTO ......
  21. 21. use Test::More;use Brownie::Session;# external servermy $session = Brownie::Session->new( driver => Mechanize, app_host => http://app.example.com:5000,);# PSGI appmy $session = Brownie::Session->new( driver => Mechanize, app => sub { ...(PSGI app)... },);
  22. 22. $ tree├── .gitignore language: perl├── .shipit perl:├── .travis.yml -"5.16"├── Changes -"5.14"├── MANIFEST.SKIP -"5.12"├── Makefile.PL -"5.10"├── README.md├── bin│   └── zamakist├── lib│   └── App│   ├── Zamakist│   │   ├── Handler│   │   │   └── GOM.pm│   │   ├── Media.pm│   │   └── Role│   │   └── Reportable.pm│   └── Zamakist.pm└── t ├── 00_compile.t ├── 01_find_permalink.t └── test_file └── The.Mentalist.S04E01.HDTV.XviD-ASAP.[VTV].Scarlet.Ribbons.avi
  23. 23. Using worker: ppp3.worker.travis-ci.org:php-1$ cd ~/builds$ git clone --depth=100 --quiet git://github.com/JEEN/p5-App-Zamakist.git JEEN/p5-App-Zamakist$ cd JEEN/p5-App-Zamakist$ git checkout -qf df10bdfea286c9933c345c84206eaa90b8f298a6$ perlbrew use 5.16$ perl --versionThis is perl 5, version 16, subversion 0 (v5.16.0) built for i686-linuxCopyright 1987-2012, Larry WallPerl may be copied only under the terms of either the Artistic License or theGNU General Public License, which may be found in the Perl 5 source kit.Complete documentation for Perl, including FAQ lists, should be found onthis system using "man perl" or "perldoc perl". If you have access to theInternet, point your browser at http://www.perl.org/, the Perl Home Page.$ cpanm --versioncpanm (App::cpanminus) version 1.5017$ cpanm --quiet --installdeps --notest .Successfully installed Text-CharWidth-0.04Successfully installed Text-UnicodeBox-0.03Successfully installed XML-XPathEngine-0.13Successfully installed HTML-Tree-5.02Successfully installed HTML-TreeBuilder-XPath-0.14Successfully installed HTML-Selector-XPath-0.14Successfully installed Web-Query-0.08Successfully installed Term-ReadLine-Zoid-0.078 distributions installed$ perl Makefile.PL && make testinclude /home/travis/builds/JEEN/p5-App-Zamakist/inc/Module/Install.pminclude inc/Module/Install/Metadata.pminclude inc/Module/Install/Base.pminclude inc/Module/Install/Makefile.pmCannot determine perl version info from lib/App/Zamakist.pminclude inc/Module/Install/Scripts.pminclude inc/Module/Install/Include.pminclude inc/Test/More.pminclude inc/Module/Install/WriteAll.pminclude inc/Module/Install/Win32.pminclude inc/Module/Install/Can.pminclude inc/Module/Install/Fetch.pmWriting Makefile for App::ZamakistWriting MYMETA.yml and MYMETA.jsonWriting META.ymlcp lib/App/Zamakist/Media.pm blib/lib/App/Zamakist/Media.pmcp lib/App/Zamakist.pm blib/lib/App/Zamakist.pmcp lib/App/Zamakist/Role/Reportable.pm blib/lib/App/Zamakist/Role/Reportable.pmcp lib/App/Zamakist/Handler/GOM.pm blib/lib/App/Zamakist/Handler/GOM.pmcp bin/zamakist blib/script/zamakist/home/travis/perl5/perlbrew/perls/5.16/bin/perl "-Iinc" -MExtUtils::MY -e MY->fixin(shift) -- blib/script/zamakistPERL_DL_NONLAZY=1 /home/travis/perl5/perlbrew/perls/5.16/bin/perl "-MExtUtils::Command::MM""-e""test_harness(0, inc, blib/lib, blib/arch)" t/*.tt/00_compile.t ......... okt/01_find_permalink.t .. 5/7 # http://search.gomtv.com/searchjm.gom?key=The.Mentalist.S04E01.HDTV.XviD-ASAP.%5BVTV%5D.Scarlet.Ribbons&preface=0# http://gom.gomtv.com/jmdb/view.html?intSeq=808364&preface=0&spage=1Wide character in print at /home/travis/perl5/perlbrew/perls/5.16/lib/5.16.0/Test/Builder.pm line 1759.# [통합] The.Mentalist.S04E01.HDTV.XviD-ASAPt/01_find_permalink.t .. okAll tests successful.Files=2, Tests=8, 10 wallclock secs ( 0.03 usr 0.01 sys + 1.79 cusr 0.10 csys= 1.93 CPU)Result: PASSDone. Build script exited with: 0
  24. 24. Jenkins Job A Build #1 Build #2 Job B Build #3 Job C
  25. 25. BuildScheduler Project Checkout/Update SCM : SVN/Git Builder : batch/shell Build Workspace Recorder : Clover/ Checkstyle PostBuild Notifier : Email/IM
  26. 26. $ prove -lv --timer --formatter TAP::Formatter::JUnit t/*
  27. 27. $ cover -report clover
  28. 28. $ measureperl-checkstyle --max_sub_lines 60 --max_sub_mccabe_complexity 10 --directory lib > checkstyle-result.xml
  29. 29. http://www.ibm.com/developerworks/kr/aix/library/au-cleancode/
  30. 30. if ($var) +1unless ($var) +1if ($var && $var2) +2if ($var || $var2) +2my $var = $solo || ‘couple’; +1my $var = $yongbin eq ‘is_couple’ ? 1 : 0; +2
  31. 31. 39 sub gen_attr { 40     my ($self, $req, $prop) = @_;41 42     my %attr = ();43     my $sort  = $req->{sort} || id;44     my $order = $req->{order} || desc;45 46     $order = desc unless $order =~ /^(?:desc|asc)$/;47     $sort  = id   unless $sort  =~ /^(?:id)$/;48 49     $attr{order_by} = { "-$order" => "me.$sort" };50     $attr{page} = $req->{page} || 1;51     $attr{rows} = $req->{num} || 30;52     $attr{page} = 1  unless $attr{page} =~ /^d+$/;53     $attr{rows} = 30 unless $attr{rows} =~ /^(?:30|50|100)$/;54     %attr;55 }
  32. 32. SILEXY CI

×