Perl web app 테스트전략
Upcoming SlideShare
Loading in...5
×
 

Perl web app 테스트전략

on

  • 1,912 views

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

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

Statistics

Views

Total Views
1,912
Views on SlideShare
1,245
Embed Views
667

Actions

Likes
2
Downloads
14
Comments
0

5 Embeds 667

http://jeen.tistory.com 642
http://www.hanrss.com 13
http://deoxygenized11.yatopa.com 6
https://twitter.com 3
http://deoxygenized11.rssing.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Perl web app 테스트전략 Perl web app 테스트전략 Presentation Transcript

    • https://metacpan.org/source/JJNAPIORK/Catalyst-Runtime-5.90016/t
    • https://metacpan.org/source/JJNAPIORK/Catalyst-Runtime-5.90016/t/ dead_recursive_chained_attributes.t
    • TestAnythingProtocol
    • cpantesters.org
    • 26,171Number of CPAN Distributions on CPAN 2012. 10. 19
    • 23,816,487Number of CPAN Testers Reports 2012. 10. 19
    • Test::MockObject Test::Class Test::Git Test::DeepTest::FITesque Test::TCP Test::mysqld Test::.... Test::YAML
    • Test::MostTest::MoreTest::Simple
    • Test::Simpleok( <expression>, <description> );
    • 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?);
    • 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: {}
    • 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);
    • TAP::Formatter::HTML
    • #!/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__..................
    • t/ 001-xss.t 002-sql-injection.t 003-directory-indexing.t 004-filedownload.t 005-path-location.t 006-os-command.t ... ... ...
    • $ 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
    • 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();
    • └── 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
    • 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/, ‘댓글 등록확인’);
    • schema.sqlCREATE TABLE ...CREATE TABLE ...... DBIx::Class::Fixtures DBIx::Class::Migrationdata.sql / jsonINSERT INTO ...INSERT INTO ......
    • 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)... },);
    • $ 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
    • 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
    • Jenkins Job A Build #1 Build #2 Job B Build #3 Job C
    • BuildScheduler Project Checkout/Update SCM : SVN/Git Builder : batch/shell Build Workspace Recorder : Clover/ Checkstyle PostBuild Notifier : Email/IM
    • $ prove -lv --timer --formatter TAP::Formatter::JUnit t/*
    • $ cover -report clover
    • $ measureperl-checkstyle --max_sub_lines 60 --max_sub_mccabe_complexity 10 --directory lib > checkstyle-result.xml
    • http://www.ibm.com/developerworks/kr/aix/library/au-cleancode/
    • if ($var) +1unless ($var) +1if ($var && $var2) +2if ($var || $var2) +2my $var = $solo || ‘couple’; +1my $var = $yongbin eq ‘is_couple’ ? 1 : 0; +2
    • 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 }
    • SILEXY CI