Upgrade to Pro — share decks privately, control downloads, hide ads and more …

テストを遅くしないように気をつけること

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for kkkw kkkw
June 22, 2017

 テストを遅くしないように気をつけること

Avatar for kkkw

kkkw

June 22, 2017

More Decks by kkkw

Other Decks in Programming

Transcript

  1. テストしたいコード AB テスト用に取ってきたユーザーを A グループとB グループに分ける class ServiceUser { public

    function get_ab_groups(){ $users = User::get_something(); // 時間 SQL User 配列 返 $a = $b = []; foreach($users as $user){ if($user->id % 2 === 0) $a[] = $user; else $b[] = $user; } return [ 'a' => $a, 'b' => $b, ]; } }
  2. こうすると早くはできる $users = array_map(function($i){ return User::forge(['id'=> $i]); }, range(1,2)); $mock

    = Mockery::mock('alias:' . User::class); $mock->shouldReceive('get_something')->andReturn($users); $actual = (new ServiceUser())->get_ab_groups(); assertSomething($actual);