SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
Agileな
Agile
開発現場での
                                           2008
                                          10/25



実践例
A practice in the Agile development team

                             岸田 健一郎
                       Ken-ichirou Kishida
                        CakePHP Conference Tokyo
• 岸田 健一郎
 Ken-ichirou Kishida

• 永和システムマネジメント所属、
 Eiwa System Management, Inc. => www.esm.co.jp
 オブジェクト倶楽部
 ObjectClub => http://ObjectClub.jp

• CakePHP暦 => 2年半ぐらい

• PHP/JavaScript/ActionScript/HTML
  /CSS etc…..
 [Technote] http://my.opera.com/sizuhiko/blog/


                                  CakePHP Conference Tokyo
CakePHP Conference Tokyo
実践例とするプロジェクト
• 中小企業向け業務パッケージ

• 2008年5月ぐらいから10月末まで2名で、
  およそ12人月ぐらい

• CakePHP1.2採用の理由は多言語(国際
  化)対応が必要だったため

• Cake内部に手を加えたのはScaffold出力
  メッセージの日本語化だけ
                CakePHP Conference Tokyo
今日はAgileについて
語る訳ではありません

Today does not necessarily talk detail about Agile.




                               CakePHP Conference Tokyo
代表的な手法である
  EXxtreme Programming

開発プラクティスを
どうやって適用したか
   紹介します
  Today’s Contents “How to apply XP”
                       CakePHP Conference Tokyo
•テスト駆動
•リファクタリング
•ペアプロ
•朝会、ふりかえり
•Etc …
        CakePHP Conference Tokyo
•テスト駆動 => Test Driven Development
•リファクタリング
•ペアプロ
•朝会、ふりかえり
•Etc …
                    CakePHP Conference Tokyo
テスト駆動開発 :
1.   クラスのスケルトンを作成する
2.   テストコードを書く
3.   テストを実行する => もちろん失敗
4.   テストにパスする簡単な実装をする
5.   テストを実行する => 成功するまで
6.   リファクタリング・・・

               CakePHP Conference Tokyo
テスト駆動開発について
詳しく知りたい方は・・


和田卓人のテスト駆動開発講座


         CakePHP Conference Tokyo
今日のポイント ~Today’s highlight
• テスト書くのなんて面倒だなぁ
  => と思っているアナタ

• テスト書いてみたけど動かなかった
  => そんなアナタ

• テストコードのサンプルってないの?
  => とお困りのアナタ

                 CakePHP Conference Tokyo
CakePHPは
テスト駆動開発向きか?

Is CakePHP for test drive development?




                       CakePHP Conference Tokyo
基本的に戻り値が連想配列なんで、空の実
装に対して先にアサーションすると、
FAILEDだけでなくERROR
(undefined index) だらけになる

→テストコードが正しいのか判断できない
              CakePHP Conference Tokyo
そのために
メンバ変数定義して
Set::map()使うの?

        CakePHP Conference Tokyo
なので、ある程度実装し
てからテストを書くと吉

  After writing simple programming,
  it is good to write a test !!




                        CakePHP Conference Tokyo
適用プロジェクトの規模
分類           ファイル数         TestCase 評価数
Model        22(43Table)        14       989
Controller          23          12       878
Component             8              9   423
View              159        -----       -----
Helper              15               5      26
Shell                 3              3   113

                           CakePHP Conference Tokyo
Keep :
• Cakeがβ→RC1→RC2→RC3と変化し
  ても影響度がすぐわかった

• デグレはほとんどない

• 他のメンバーが書いたコードの意味を把
  握しやすい


               CakePHP Conference Tokyo
Problem :
• テストケース考慮モレにバグが潜んでい
  た

• Controllerのテストは書きにくいのであ
  まり書いていない

• テストコードが長すぎて失敗ケースだけ
  やり直したいのに時間がかかり過ぎ

               CakePHP Conference Tokyo
Try :
• テストコードを分割しよう

• Controller,Comonent,Model それぞ
  れどこに何を書くかパターン化してテス
  ト漏れを防ぎたい

• テストメソッド単位で実行できるように
  test.phpやTestCaseを書き換えたい

                   CakePHP Conference Tokyo
Test 書いてますか?

  書いている人は挙手にご協力ください



Please raise your hand if you write code of test !



                              CakePHP Conference Tokyo
そこで Test を書くのに
 役立つ「虎の巻」を
   紹介します

 Some hints of how to write code of Test



                          CakePHP Conference Tokyo
つまりTestCaseの
文法を解説する訳では
   ありません

  Today does not necessarily
  talk to syntax of TestCase.
                    CakePHP Conference Tokyo
TestCaseの記法



  詳しくはコチラで見てください・・・




http://book.cakephp.org/ja/view/160/テスト-Testing
                            CakePHP Conference Tokyo
Level:0 DBは$testで設定する
class DATABASE_CONFIG {
        var $default = array(
        );
        var $test = array(
                 'driver' => 'mysql',
                 'persistent' => false,
                 'host' => 'localhost',
                 'port' => '',
                 'login' => 'root',
                 'password' => 'root',
                 'database' => ‘post',
                 'schema' => '',
                 'prefix' => 'test_suite_',
                 'encoding' => 'utf8'
        );
}
                                          CakePHP Conference Tokyo
Level:1 関連は自分でセットする
class PostTest extends Post {
   var $useDbConfig = 'test_suite';
}
class CategoryTest extends Category {
   var $useDbConfig = 'test_suite';
}
                             しなくても動くけど、
                             JOINされません
class PostTestCase extends CakeTestCase {
  function setUp() {
     $this->Model = new PostTest();
    $this->Model->Category
           = new CategoryTest();
                                      CakePHP Conference Tokyo
Level:2 名前付け重要
post.test.php :                     同じ名前があると
class PostTest extends Post {
   var $useDbConfig = 'test_suite'; GroupTestで「既に存在
}                                   するクラス」になり、失
                                    敗する。
class CategoryTest extends Category {

                                    なので、上の方はテスト
   var $useDbConfig = 'test_suite';
}

                                    ケース名+モデル名とい
                                    う規則で、
category.test.php :
                                       PostTestCategory
classCategoryTest                      とすると良い。
                                extends Category {
   var $useDbConfig = 'test_suite';
}
                                                 CakePHP Conference Tokyo
Level:3 fixtureに注意
class PostFixture extends CakeTestFixture {
       var $name = ‘Post';
      var $import = array('model'=>‘Post');

      function create() {
           return false; スキーマ情報をイン
      }                   ポートすると、テーブ
                          ルが自動生成されない
      function drop() {
           return false;
      }
}

                                    CakePHP Conference Tokyo
Level:4 コンポーネントは自分でセット
class LoginComponent extends Object {
  var $components = array('Session');


         コンポーネントのテストで、そのコンポー
         ネントが別のコンポーネントを使っている
         場合、初期化されないので注意
class LoginComponentTest extends CakeTestCase {
   function setUp() {
      $this->Controller = &new LoginTestController();
      $this->Login = &new LoginComponent();
     $this->Login->Session = &new SessionComponent();


                                                  CakePHP Conference Tokyo
Level:5 独自FormHelperは初期化が複雑

class AppFormHelper extends FormHelper {
}

class AppFormTest extends CakeTestCase {
   function setUp() {
     parent::setUp();
     Router::reload();
     $this->AppForm = new AppFormHelper();
     $this->AppForm->Html =& new HtmlHelper();
     $this->Controller =& new AppFormTestController();
     $this->View =& new View($this->Controller);
}
          CakeのFormHelperテストの初期化を拝
          借しましょう。
                                           CakePHP Conference Tokyo
Level:6 計算結果はassertIdentical

function test01.12300は前後の0が省略フォーマットされる() {
    $this->assertIdentical('1.123',
     $this->NumberUtil->formatFloat(quot;01.12300quot;));
}



function test01.12300は前後の0が省略フォーマットされる() {
  $this->assertEqual('1.123',
         もし結果が“1.12300”と帰ってきても、
   $this->NumberUtil->formatFloat(quot;01.12300quot;));
         成功してしまいます。
}


                              CakePHP Conference Tokyo
Level:7 Shellテストの決まり
if(!class_exists('Shell')){
    class Shell extends Object {}
}                      クラスがない場合がある
                     ので先頭でチェック
App::import(
    'Vendor', 'MonthlyUpdateShell',
    array(
      'file' => 'Shells'.DS.'monthly_update.php‘
));                    fileを指定してimportしよう
                            CakePHP Conference Tokyo
Level:8 Controllerにロジックを書かない

• aclとかAuthとかセッションとか依存
  関係が多すぎて大変

• なるべくComponentを使おう

• でもWebAPIとかAjaxとか、結果を評
  価したい場合もある

                 CakePHP Conference Tokyo
コントローラでテストしたもの
• WebAPI (REST Interface)
  testAction, result=>render でチェック

• エラーページへリダイレクトされる
  かWebTestCaseでチェック
  ※ただしfixtureもMockも使えません


                    CakePHP Conference Tokyo
WebAPIのチェック
$data = array(‘Post' => array(
     'id from' => 16, // ここから
     'id to' => 27, // ここまで
));
$result = $this->testAction(
     ‘/api/posts/index',
     array('return'=>'render', 'data' => $data));

$xml = Set::reverse(new Xml($result));
$this->assertEqual(11,
      count($xml[‘Posts.index'][‘Posts'][‘Post']));
                                  CakePHP Conference Tokyo
WebTestCaseでのチェック
function testセッションエラーの場合エラー700が戻る() {
   // ログインしておく
   $this->addHeader('Accept-Language:ja');
    $this->assertTrue($this->get('/users/login'));
    $this->assertTitle('ログイン');
    $this->setFieldByName('data[User][account]', 'admin');
    $this->setFieldByName('data[User][password]','password');
    $this->assertTrue($this->clickSubmit('Login'));
    $this->assertTitle(‘ホーム');
    $this->addHeader('User-Agent: Session Error);
    // どこかのページへ遷移
    $this->assertTrue($this->get('/users/index'));
    // HTTPレスポンスの評価
    $this->assertResponse('700');
    $this->assertTitle(‘セッションエラー');
}
                                                     CakePHP Conference Tokyo
Level:9 Mockは積極的に使おう

• テストごとに前工程をダラダラ書く
  のはムダ

• テストコードがすっきりして本来テ
  ストしたい目的がわかりやすい

• ただし、RC3でコントローラテスト
  する場合は使用方法に注意・・・
            CakePHP Conference Tokyo
MockObjectの使い方

class UsersControllerTestCase extends CakeTestCase {
   function setUp() {
      Mock::generate('LoginComponent');
      $this->Login = &new MockLoginComponent();
  }
  function startController(&$controller, $params) {
       $controller->Login = $this->Login;
  }



                                  CakePHP Conference Tokyo
MockObjectの使い方
class UsersControllerTestCase
                     extends CakeTestCase {
  function testログインしているユーザ名を取得() {
     $this->Login->setReturnValue(
         ‘getLoginName', ‘岸田健一郎’);
    $result = $this->testAction(
          '/api/users/1/name',
          array('return'=>'render'));
    $this->assertEqual(
         ‘岸田健一郎’, $result);
                              CakePHP Conference Tokyo
1.2 RC3 では・・・
class UsersControllerTest extends CakeTestCase {
function startController(&$controller, $params) {
      $controller->Login = $this->Login;
      $controller->Component->
       __loaded['Login'] = $this->Login;
  }

コントローラ内でのコンポーネント初期化タイミ
ングがstartControllerより後になったので __loaded
でブロックしないとMockが使えないが・・・

                                 CakePHP Conference Tokyo
内部変数に直接はアレなので
App::import('Controller', ‘Users');

class UsersControllerTestController
extends UsersController {
   var $LoginMock;
   function beforeFilter(){
     $this->Login = $this->LoginMock;
     return parent::beforeFilter();
   } テスト用のコントローラーを作って、
} beforeFilterでモックと置き換えましょう
                           CakePHP Conference Tokyo
startControllerを変更
class UsersControllerTest extends CakeTestCase
{
  function startController(&$controller, $params)
  {
      $controller->LoginMock
          = $this->Login;
  }

  でもtestActionってURLからコントローラを生成
  するから独自コントローラ使えなくネ??
                             CakePHP Conference Tokyo
実はパラメータで変えられます
class UsersControllerTestCase
                     extends CakeTestCase {
  function testログインしているユーザ名を取得() {

    $result = $this->testAction(
      '/api/users/1/name',
      array(
         'return'=>'render',
          'controller'=>'UsersControllerTest',
    ));


                             CakePHP Conference Tokyo
困ったら
• Booksを見よう
  翻訳された皆様に感謝!!
   でも書いてないこともタマにある
   => 今日のスライドが参考になれば・・

• Cake本体のテストコード見る
  Cake自体の理解度も向上する


              CakePHP Conference Tokyo
まとめ
• 面倒がらずに一度書けば、何度でも役に
  立つのがテストコード

• 初期化に罠が多いので、注意しよう。逆
  にテストケース自体は普通の書き方。

• Cake本体のテストコードがお手本


             CakePHP Conference Tokyo
これで明日から
  日曜日ですが・・・




         CakePHP Conference Tokyo
Testで
みんなHappyに

     CakePHP Conference Tokyo
ご清聴ありがとう
 ございました

    CakePHP Conference Tokyo

Contenu connexe

Similaire à Agileな開発現場での実践例

yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
Yusuke Wada
 
JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009
gyuque
 
Ohp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 MojiretsuOhp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 Mojiretsu
sesejun
 
Open Source Type Pad Mobile
Open Source Type Pad MobileOpen Source Type Pad Mobile
Open Source Type Pad Mobile
Hiroshi Sakai
 
Web應用程式以及資安問題的探討
Web應用程式以及資安問題的探討Web應用程式以及資安問題的探討
Web應用程式以及資安問題的探討
Mu Chun Wang
 
事件模型探究
事件模型探究事件模型探究
事件模型探究
ematrix
 

Similaire à Agileな開発現場での実践例 (20)

20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
 
Jslunch6
Jslunch6Jslunch6
Jslunch6
 
Spring基础教程
Spring基础教程Spring基础教程
Spring基础教程
 
Spring Framework勉強会
Spring  Framework勉強会Spring  Framework勉強会
Spring Framework勉強会
 
Seize The Cloud
Seize The CloudSeize The Cloud
Seize The Cloud
 
GAE/J 開発環境でJDO入門
GAE/J 開発環境でJDO入門GAE/J 開発環境でJDO入門
GAE/J 開発環境でJDO入門
 
JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009
 
Ohp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 MojiretsuOhp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 Mojiretsu
 
S2Flex2
S2Flex2S2Flex2
S2Flex2
 
Open Source Type Pad Mobile
Open Source Type Pad MobileOpen Source Type Pad Mobile
Open Source Type Pad Mobile
 
Ruby on Rails Tutorial Part I
Ruby on Rails Tutorial Part IRuby on Rails Tutorial Part I
Ruby on Rails Tutorial Part I
 
What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
Windows PowerShell V2 の新機能
Windows PowerShell V2 の新機能Windows PowerShell V2 の新機能
Windows PowerShell V2 の新機能
 
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編
 
4200 Kte7.0 Training V1.0
4200 Kte7.0 Training V1.04200 Kte7.0 Training V1.0
4200 Kte7.0 Training V1.0
 
misspattern
misspatternmisspattern
misspattern
 
Web應用程式以及資安問題的探討
Web應用程式以及資安問題的探討Web應用程式以及資安問題的探討
Web應用程式以及資安問題的探討
 
事件模型探究
事件模型探究事件模型探究
事件模型探究
 
樽家昌也 (日本Rubyの会)
樽家昌也 (日本Rubyの会) 樽家昌也 (日本Rubyの会)
樽家昌也 (日本Rubyの会)
 

Plus de kishida4slideshare (7)

Behat入門
Behat入門Behat入門
Behat入門
 
Phpmatsuri2010
Phpmatsuri2010Phpmatsuri2010
Phpmatsuri2010
 
CakePHPのWebTestCaseでfixtureを使う
CakePHPのWebTestCaseでfixtureを使うCakePHPのWebTestCaseでfixtureを使う
CakePHPのWebTestCaseでfixtureを使う
 
箱根湯けむり事件簿
箱根湯けむり事件簿箱根湯けむり事件簿
箱根湯けむり事件簿
 
CakeにTestがやってきた
CakeにTestがやってきたCakeにTestがやってきた
CakeにTestがやってきた
 
Opera Backstage Tokyo 2008' ライトニングトークス
Opera Backstage Tokyo 2008' ライトニングトークスOpera Backstage Tokyo 2008' ライトニングトークス
Opera Backstage Tokyo 2008' ライトニングトークス
 
Web2.0 講演スライド 2008/2/26
Web2.0 講演スライド 2008/2/26Web2.0 講演スライド 2008/2/26
Web2.0 講演スライド 2008/2/26
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Agileな開発現場での実践例