想定読者
テストケースの網羅に苦しんでいるみなさま。
この記事はなんだ?
以前、ペアワイズ法を用いたテストケース削減の手法の紹介LTをしました。好評だったので、デモ部分も含めて紹介する記事です。
LT内容
デモ
pict
pictをインストールして、2因子間網羅率100%の場合のテスト件数、3因子間網羅率100%の場合のテスト件数を確認してみる。
$ git clone https://github.com/Microsoft/pict.git
$ cd pict
$ make
$ sudo install -m 0755 pict /usr/local/bin/pict
sample_1.txt
user_id: none,valid,non-exist,not-mail
password: none,valid,invalid
agreement: none,agree,disagree
$pict ./sample_1.txt
user_id password agreement
not-mail none none
not-mail invalid agree
non-exist none disagree
not-mail valid disagree
non-exist valid none
valid invalid disagree
valid none agree
none none disagree
valid valid none
none valid agree
none invalid none
non-exist invalid agree
$pict ./sample_1.txt /o:3
<- /o:3
で3因子間網羅オプションを設定
user_id password agreement
non-exist valid none
none none agree
not-mail invalid agree
non-exist valid agree
valid valid disagree
valid invalid none
valid none agree
valid invalid agree
non-exist none agree
not-mail valid disagree
non-exist none disagree
valid valid none
non-exist invalid agree
not-mail valid none
none valid disagree
valid none none
not-mail invalid disagree
not-mail none none
not-mail none agree
none valid agree
valid none disagree
valid invalid disagree
none invalid none
non-exist invalid disagree
non-exist invalid none
non-exist valid disagree
none invalid agree
non-exist none none
none none disagree
none valid none
not-mail none disagree
not-mail invalid none
not-mail valid agree
valid valid agree
none none none
none invalid disagree
ビジネスルールによる禁則処理1を追加した場合のテストパターンの変化を確認。
sample_2.txt
user_id: none,valid,non-exist,not-mail
password: none,valid,invalid
agreement: none,agree,disagree
if [user_id] = "none" OR [password] = "none" then [agreement] = "none";
$pict ./sample_2.txt
user_id password agreement
non-exist valid none
valid valid agree
valid none none
non-exist none none
non-exist invalid agree
not-mail invalid disagree
none valid none
not-mail none none
none invalid none
valid invalid disagree
none none none
non-exist valid disagree
not-mail valid agree
Pairwiser
(2017/11/9追記)2017/12/1を以ってサービス終了
pictと同じ条件のデータを入力した画面操作の紹介
こっちはcsvのimport/exportができる & GUIなので、エンジニア以外の人でもパターン生成しやすい。
※importはこんな感じ(UTF-8じゃないとうまくいかないっぽい)
'メール','','aaa','aaa@bb','aaa@bb.jp'
RSpecで使ってみる
repec-parameterizedを使います。
- Gemfileに追加 :
gem 'rspec-parameterized'
- helperに追加 :
require 'rspec-parameterized'
- テストケースの出力をちょっといじって、ぺたり。 2
describe 'pairwise sign in' do
where(:id, :user_id, :name, :password, :password_confirm, :error_count) do
[
[1, 'name @name.jp','name','','nnn', 2],
[2, '','','nnn','', 5],
[3, 'name','name@name.jp','nnn','bbbbbb', 3],
[4, '','name name','nnn','rails5', 4],
[5, '','','nnn','bbbbbb', 5],
[6, 'name@name.jp','name@name.jp','nnn','nnn', 1],
~略~
]
end
with_them do
it "#{params[:id]} => #{params[:error_count]} error" do
testing_params = {
user: {
name: name,
email: user_id,
password: password,
password_confirmation: password_confirm
}
}
post users_path, {params: testing_params}
if error_count == 0
expect(response.status).to eq(302)
else
expect(response.body).to include(error_count.to_s + ' error')
end
end
end
end
感想的なもの
- 銀の弾丸ではないけれど、なんとなくテストケースを考えるよりはるかに楽になるはず!!