integration testing practice using perl

56
Integration Testing Practice using Perl Masaki Nakagawa / @ikasam_a DeNA Co., Ltd.

Upload: masaki-nakagawa

Post on 05-Dec-2014

3.070 views

Category:

Technology


0 download

DESCRIPTION

YAPC::Asia 2013

TRANSCRIPT

Page 1: Integration Testing Practice using Perl

Integration Testing Practice using Perl

Masaki Nakagawa / @ikasam_aDeNA Co., Ltd.

Page 2: Integration Testing Practice using Perl

About Me

• Masaki Nakagawa

• @ikasam_a

• github.com/masaki

• metacpan.org/author/MASAKI

• Yokohama.pm

Page 3: Integration Testing Practice using Perl

Ad.

Page 6: Integration Testing Practice using Perl

http://yapcasia.org/2013/talk/show/9c756568-ea92-11e2-ba88-5f716aeab6a4

What's new in Carton & cpanm(11:40 ~ 12:00)

Page 8: Integration Testing Practice using Perl

Software Engineer in Testat DeNA

Masaki Nakagawa / @ikasam_aDeNA Co., Ltd.

http://www.slideshare.net/masaki/software-engineer-in-test-at-dena

Page 9: Integration Testing Practice using Perl

Testing Casual Talks #2

2013/11/xx

Page 10: Integration Testing Practice using Perl

Works

• DeNA Co.,Ltd.

• SWET Group, Platform System Dept.

• Founder of Platform QA Team (2012/01~)

• Manager of SWET Group (2013/08~)

Page 11: Integration Testing Practice using Perl

http://dena.com/topics/2013/07/swettechtalk33.php

with @shyouhei

Page 12: Integration Testing Practice using Perl

YAPC::Asia Tokyo 2013 特別座談会 「Rubyの良いところ語ってください ~そんなPerlで大丈夫か?~」

(13:00 ~ 14:00)

http://yapcasia.org/2013/talk/show/c6b08f02-f293-11e2-ba15-895a6aeab6a4

Page 13: Integration Testing Practice using Perl

Roles

• SWET (Software Engineer in Test)

• TE (Test Engineer)

Page 14: Integration Testing Practice using Perl

What is SWET?

• a developer role for testing

• write test framework

• build test environments

• write test codes

Page 17: Integration Testing Practice using Perl

Several Names

• SWET @DeNA

• SET (Software Engineer in Test) @Google

• SDET (Software Development Engineer in Test) @Microsoft

Page 18: Integration Testing Practice using Perl

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

Page 19: Integration Testing Practice using Perl

Developer Productivity

• to improve productivity

• Base Technology

• Development Infrastructure

• as SWET

• support developer testing

• support development with tests

Page 20: Integration Testing Practice using Perl

Testing Activities

SHOULD

be in Developments

Page 21: Integration Testing Practice using Perl

SWET GroupMission Statement

• For platform engineers

• To develop new features

• Should keep the quality of platform system

Page 22: Integration Testing Practice using Perl

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

Page 23: Integration Testing Practice using Perl

What is SWET?

• a developer role for testing

• write test framework

• build test environments

• write test codes

Page 24: Integration Testing Practice using Perl

How to ?

Page 25: Integration Testing Practice using Perl

Classification of Testing

Perspective Target

How What

Page 26: Integration Testing Practice using Perl

Perspective

•Developer Testing

•Acceptance Testing

Developer or User (Customer)

Page 27: Integration Testing Practice using Perl

Target

•Unit Testing

•Integration Testing

One or More

Page 28: Integration Testing Practice using Perl

How

•Black Box Testing

•White Box Testing

•Gray Box Testing

Techniques for writing tests

Page 29: Integration Testing Practice using Perl

What

•Functional Testing

•Non-Functional Testing

• Performance / Stress / Usability / ...

the Purpose of testing

Page 30: Integration Testing Practice using Perl

Classification of Testing

Perspective Target

How What

Page 31: Integration Testing Practice using Perl

Target

•Unit Testing

•Integration Testing

One or More

Page 32: Integration Testing Practice using Perl

Unit Testing

• What is “Unit” ?

• METHODs in module

• COMPONENTs in system

• ...

• Focus to input/output of unit

Page 33: Integration Testing Practice using Perl

Integration Testing

• What is “Integration”

• MODULEs (= component)

• COMPONENTs (= system)

• ...

• Consider interaction/orchestration

Page 34: Integration Testing Practice using Perl

Interaction

• Unit Testing

• ONLY Focus to Test Target

• Mocking/Stubbing OTHERs

• Integration Testing

• in Real Environments

Page 35: Integration Testing Practice using Perl

Case Study

Page 36: Integration Testing Practice using Perl

(case-1) Web API

• HTTP JSON-RPC API

• Interaction & Integration

• API Server Modules

• API Server, DB, Cache Server

Page 37: Integration Testing Practice using Perl

API Server

module module module

API ServerAPI ServerDB

API ServerAPI ServerCache

Test Client

Page 38: Integration Testing Practice using Perl

Conditions

• (IN) HTTP Request to API Server

• (OUT) JSON Response from API Server

Page 39: Integration Testing Practice using Perl

HTTP Client

• LWP::UserAgent

• Furl

Page 40: Integration Testing Practice using Perl

JSON Validation

• JSON + Test::Deep family

• T::D::Matcher, T::D::Cond

• use JSON-Schema

• https://github.com/zigorou/perl-JSV

Page 41: Integration Testing Practice using Perl

API Server

module module module

API ServerAPI ServerDB

API ServerAPI ServerCache

Test Client

Gray Box Fixture

Page 42: Integration Testing Practice using Perl

Gray Box Fixture

• DB / Cache Manipulation

• insert test-case specific data

• delete cache for continuous tests

Page 43: Integration Testing Practice using Perl

API ServerAPI ServerAPI Server

module module module

API ServerAPI ServerDB

API ServerAPI ServerCache

Test Client

Specific Server Request

Page 44: Integration Testing Practice using Perl

Specific Server Request

• LWP::UserAgent::DNS::Hosts

• Furl + “inet_aton” option

• programmable local DNS (MyDNS)

Page 45: Integration Testing Practice using Perl

Dump Messages

• LWP keeps previous request

• as HTTP::Response::request()

• Furl + “capture_request” option

Page 46: Integration Testing Practice using Perl

(case-2) Web Application

• Interaction & Integration

• Web App Modules

• like MVC

• Web App, DB, Cache Server

Page 47: Integration Testing Practice using Perl

Web Application

M V C

API ServerAPI ServerDB

API ServerAPI ServerCache

Test Browser

Page 48: Integration Testing Practice using Perl

Conditions

• (IN) HTTP Request to Web App

• (OUT) HTML Response from Web App

Page 49: Integration Testing Practice using Perl

Browser / User Agent

• WWW::Mechanize

• Selenium::Remote::Driver

• Wight

• Brownie

Page 50: Integration Testing Practice using Perl

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

Page 51: Integration Testing Practice using Perl

Test Browser Test Browser

Web Application

M V C

API ServerAPI ServerDB

API ServerAPI ServerCache

Switch Browser

Page 52: Integration Testing Practice using Perl

Switch Browser

• Browser can’t touch HTTP Header

• Emulator can’t parse JavaScript

• Save/Restore pseudo browser state

Page 53: Integration Testing Practice using Perl

Other Modules

• Test::Ika (RSpec for Perl)

• Test::Requires::Env

• App::envfile

• Config::Pit

Page 54: Integration Testing Practice using Perl

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;

Page 55: Integration Testing Practice using Perl

Test::Requires::Env

use Test::Requires::Env qw( USERNAME PASSWORD);

Page 56: Integration Testing Practice using Perl

Questions?