Upload
masaki-nakagawa
View
3.070
Download
0
Embed Size (px)
DESCRIPTION
YAPC::Asia 2013
Citation preview
Integration Testing Practice using Perl
Masaki Nakagawa / @ikasam_aDeNA Co., Ltd.
About Me
• Masaki Nakagawa
• @ikasam_a
• github.com/masaki
• metacpan.org/author/MASAKI
• Yokohama.pm
Ad.
http://gihyo.jp/magazine/wdpress/archive/2013/vol75
http://gihyo.jp/book/2013/978-4-7741-5864-8
http://yapcasia.org/2013/talk/show/9c756568-ea92-11e2-ba88-5f716aeab6a4
What's new in Carton & cpanm(11:40 ~ 12:00)
Software Engineer in Testat DeNA
Masaki Nakagawa / @ikasam_aDeNA Co., Ltd.
http://www.slideshare.net/masaki/software-engineer-in-test-at-dena
Testing Casual Talks #2
2013/11/xx
Works
• DeNA Co.,Ltd.
• SWET Group, Platform System Dept.
• Founder of Platform QA Team (2012/01~)
• Manager of SWET Group (2013/08~)
http://dena.com/topics/2013/07/swettechtalk33.php
with @shyouhei
YAPC::Asia Tokyo 2013 特別座談会 「Rubyの良いところ語ってください ~そんなPerlで大丈夫か?~」
(13:00 ~ 14:00)
http://yapcasia.org/2013/talk/show/c6b08f02-f293-11e2-ba15-895a6aeab6a4
Roles
• SWET (Software Engineer in Test)
• TE (Test Engineer)
What is SWET?
• a developer role for testing
• write test framework
• build test environments
• write test codes
http://googletesting.blogspot.jp/2011/02/how-google-tests-software-part-two.html
Several Names
• SWET @DeNA
• SET (Software Engineer in Test) @Google
• SDET (Software Development Engineer in Test) @Microsoft
Google’s “SET”
• Google Testing Blog• http://googletesting.blogspot.com
• How Google Tests Software• http://googletesting.blogspot.jp/2011/01/how-google-tests-software.html
Developer Productivity
• to improve productivity
• Base Technology
• Development Infrastructure
• as SWET
• support developer testing
• support development with tests
Testing Activities
SHOULD
be in Developments
SWET GroupMission Statement
• For platform engineers
• To develop new features
• Should keep the quality of platform system
About SWET Group
• To verify the Platform System
• To write AUTOMATION tests
• To improve Platform System quality
is NOT a tester, is a TEST ENGINEER
What is SWET?
• a developer role for testing
• write test framework
• build test environments
• write test codes
How to ?
Classification of Testing
Perspective Target
How What
Perspective
•Developer Testing
•Acceptance Testing
Developer or User (Customer)
Target
•Unit Testing
•Integration Testing
One or More
How
•Black Box Testing
•White Box Testing
•Gray Box Testing
Techniques for writing tests
What
•Functional Testing
•Non-Functional Testing
• Performance / Stress / Usability / ...
the Purpose of testing
Classification of Testing
Perspective Target
How What
Target
•Unit Testing
•Integration Testing
One or More
Unit Testing
• What is “Unit” ?
• METHODs in module
• COMPONENTs in system
• ...
• Focus to input/output of unit
Integration Testing
• What is “Integration”
• MODULEs (= component)
• COMPONENTs (= system)
• ...
• Consider interaction/orchestration
Interaction
• Unit Testing
• ONLY Focus to Test Target
• Mocking/Stubbing OTHERs
• Integration Testing
• in Real Environments
Case Study
(case-1) Web API
• HTTP JSON-RPC API
• Interaction & Integration
• API Server Modules
• API Server, DB, Cache Server
API Server
module module module
API ServerAPI ServerDB
API ServerAPI ServerCache
Test Client
Conditions
• (IN) HTTP Request to API Server
• (OUT) JSON Response from API Server
HTTP Client
• LWP::UserAgent
• Furl
JSON Validation
• JSON + Test::Deep family
• T::D::Matcher, T::D::Cond
• use JSON-Schema
• https://github.com/zigorou/perl-JSV
API Server
module module module
API ServerAPI ServerDB
API ServerAPI ServerCache
Test Client
Gray Box Fixture
Gray Box Fixture
• DB / Cache Manipulation
• insert test-case specific data
• delete cache for continuous tests
API ServerAPI ServerAPI Server
module module module
API ServerAPI ServerDB
API ServerAPI ServerCache
Test Client
Specific Server Request
Specific Server Request
• LWP::UserAgent::DNS::Hosts
• Furl + “inet_aton” option
• programmable local DNS (MyDNS)
Dump Messages
• LWP keeps previous request
• as HTTP::Response::request()
• Furl + “capture_request” option
(case-2) Web Application
• Interaction & Integration
• Web App Modules
• like MVC
• Web App, DB, Cache Server
Web Application
M V C
API ServerAPI ServerDB
API ServerAPI ServerCache
Test Browser
Conditions
• (IN) HTTP Request to Web App
• (OUT) HTML Response from Web App
Browser / User Agent
• WWW::Mechanize
• Selenium::Remote::Driver
• Wight
• Brownie
use Test::More;use Brownie::Session;
my $session = Brownie::Session->new( driver => 'Mechanize', app_host => 'http://app.example.com/',);
$session->visit('/');is $session->title => 'Title';
$session->fill_in('User Name' => 'brownie');$session->fill_in('Email Address' => '[email protected]');$session->click_button('Login');like $session->source => qr/Welcome (.+)/;
done_testing;
e.g.) Brownie
Test Browser Test Browser
Web Application
M V C
API ServerAPI ServerDB
API ServerAPI ServerCache
Switch Browser
Switch Browser
• Browser can’t touch HTTP Header
• Emulator can’t parse JavaScript
• Save/Restore pseudo browser state
Other Modules
• Test::Ika (RSpec for Perl)
• Test::Requires::Env
• App::envfile
• Config::Pit
Test::Ikause Test::Ika;use Test::More; describe 'nekokak API' => sub { my $client; before_each { $client = NekokakClient->new(icon => 1); }; it 'should return response with icon' => sub { my $res = $client->request(method => 'dis'); ok $res->{icon}; };}; runtests;
Test::Requires::Env
use Test::Requires::Env qw( USERNAME PASSWORD);
Questions?