LoginSignup
1
1

More than 5 years have passed since last update.

Calabash-Androidのテストの書き方まとめ

Posted at

Calabashのテストの書き方についてテストの書き方についてあまり記事がなかったのでまとめてみる
https://github.com/calabash/calabash-android

Calabashのセットアップ

ココらへんみたらだいたいわかる
http://toshihirock.blogspot.jp/2014/03/calabash-androidandroid.html
http://www.slideshare.net/chariderpato/calabashbdd

実行

.setting_calabashが必要な時・いらない時→デバッグビルドの時はいらない、間違えて作った時は消すとOK
http://www.atmarkit.co.jp/ait/articles/1412/16/news043_3.html

  • 既に入っているアプリはアンインストールされて新しいAPKがインストールされる→初期起動扱い

テストの書き方

featureファイルの役割

デフォルトで作られるmy_first.featureがどういう役割なのかを探ってみる

Featureごとに新しいアプリをインストール

  • featureファイルの実行ごとに既存のアプリをアンインストールし、新しいアプリがインストールされる
  • featureファイルの中には1つのFeatureの宣言しかできない

これはだめ!怒られる

my_feature.feature
 Feature: 起動1

   Scenario: hogeを選択
     Then I see "hoge選択"
     Then I press view with id "button_id1"

 Feature: 起動2

   Scenario: hugaを選択
     Then I see "huga選択"
     Then I press view with id "button_id2"


正しくはこう

my_feature.feature
 Feature: 起動1

   Scenario: hogeを選択
     Then I see "hoge選択"
     Then I press view with id "button_id1"

Scenarioレベルは同じアプリを使用してアプリを起動

同じfeatureファイルの中でのシナリオは同じアプリが使用されるが、シナリオレベルではアプリは終了状態からスタートする

my_feature.feature
 Feature: 起動1

   Scenario: hogeを選択
     Then I see "hoge選択"
     Then I press view with id "button_id1"

  Scenario: hugaを選択
     Then I see "huga選択"
     Then I press view with id "button_id2"


同じふるまいをstepにまとめる

step_definitions/calabash_steps.rbを修正すると、いくつかのふるまいをまとめてメソッドのように管理できる

calabash_steps.rb
 require 'calabash-android/calabash_steps'

 Then /^gotoSearchTopKanto$/ do
         step %{I see "hoge選択"}
         step %{I press view with id "button_id1"}
 end

stepのファイルを複数に分けることも可能そう

myfirst_steps.rb
 require 'calabash-android/calabash_steps'

//以下にstepsを書いていく

step用のコードはここから参考にする
https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash-android/canned_steps.md

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1