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

Integration Testing

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Integration Testing

Avatar for Ivan Kerin

Ivan Kerin

April 25, 2014
Tweet

More Decks by Ivan Kerin

Other Decks in Technology

Transcript

  1. High Level Integration Testing • Encompass a lot of functionality

    • Don’t concentrate on edge cases • Test user experience, not implementation • Testing has to be easy™
  2. Gotchas • Slow tests don’t get run • “Develop →

    Test → Deploy” cycle • Unenforced tests don’t get run • Tests must be isolated
  3. Spiderling • Spiderling https://github.com/OpenBuildings/spiderling • PHPUnit Spiderling https://github.com/OpenBuildings/phpunit-spiderling • DB

    Fixtures https://github.com/OpenBuildings/db-fixtures • Functest https://github.com/OpenBuildings/functest • Env Backup https://github.com/clippings/env-backup
  4. Example Test Cycle • Import SQL dump, or run fixtures

    to generate one (DB Fixtures) • Set all global state to known values (Env Backup) • Start DB Transaction • Optionally Start Browser / phantomjs • Run tests • Rollback DB Transaction • Rollback global state
  5. Example • Go to edit my profile page • Enter

    Your Email! • Enter First Name • Enter Last Name • Enter About You • Upload Image Your photo! • Press Save Button! • Validate saved data
  6. <?php! ! class MeTest extends Testcase_Functest {! ! ! !

    public function test_me_edit()! ! {! ! ! $user = $this->login();! ! ! ! $this->visit('me/edit');! ! ! $this->assertHasCss('h3', array('text' =>'Edit your profile'));! ! ! ! $this->fill_in('Your Email', '[email protected]');! ! ! $this->fill_in('First name', 'Bob');! ! ! $this->fill_in('Last name', 'Smith');! ! ! $this->fill_in('description', 'new description');! ! ! $this->attach_file('Your Photo', APPPATH.'tests/image1.jpg');! ! ! ! $this->click_button('Save Profile');! ! ! ! $this->assertHasCss('.notification.success', array('text' => 'Updated'));! ! ! ! $updated_user = Jam::find('user', $user->id());! ! ! ! $this->assertEquals(Resource::url($updated_user), $this->current_path());! ! ! $this->assertEquals('[email protected]', $updated_user->email);! ! ! $this->assertEquals('Bob', $updated_user->first_name);! ! ! $this->assertEquals('Smith', $updated_user->last_name);! ! ! $this->assertEquals('image1.jpg', $updated_user->avatar->filename());! ! ! $this->assertEquals('new description', $updated_user->description);! ! }! }!
  7. Selenium class MeTest extends Testcase_Functest {! ! ! /**! !

    * @driver selenium! ! */! ! public function test_me_edit()! ! {! ! ! $user = $this->login();! ! ! ! $this->visit('me/edit');! ! ! $this->assertHasCss('h3', array('text' =>'Edit your profile'));! composer require claylo/selenium-server-standalone:dev-master! composer install! ! xvfb-run java -jar vendor/claylo/selenium-server-standalone/selenium-server-standalone-2.*.jar
  8. Phantomjs class MeTest extends Testcase_Functest {! ! ! /**! !

    * @driver phantomjs! ! */! ! public function test_me_edit()! ! {! ! ! $user = $this->login();! ! ! ! $this->visit('me/edit');! ! ! $this->assertHasCss('h3', array('text' =>'Edit your profile'));!
  9. Debugging ! public function test_me_edit()! ! {! ! ! $user

    = $this->login();! ! ! ! $this->visit('me/edit');! ! ! $this->assertHasCss('h3', array('text' =>'Edit not your profile'));! ! ! ! echo $this->find('h3');! ! ! $this->screenshot(APPROOT.'application/logs/testimage.png');! ! ! ! $this->fill_in('Your Email', '[email protected]');! ! ! $this->fill_in('description', 'new description');! ! ! ! $this->click_button('Save Profile');! ! }!