我们来看看这个测试:
userA logIn
rerun "defaultStage"
verify "defaultStage" is triggered and wait for completed
verify pipeline label of "defaultStage" is "1"
verify "secondStage" is triggered and wait for completed
verify pipeline Stage" is "1"
无可否认,测试达到了目的,验证了系统行为与期待一致。问题是这个测试中的“期待”到底是什么?
在带上用户的帽子回答这个问题的时候,我们很快意识到
verify "defaultStage" is triggered and wait for completed对于用户来说意味着:
verify pipeline label of "defaultStage" is "1"
newly created "defaultStage" should be ran in the same pipeline
而后两句:
verify "secondStage" is triggered and wait for completed意味着:
verify pipeline Stage" is "1"
next stage should be triggered automatically.
于是测试变成了:
userA logIn
rerun "defaultStage"
newly created "defaultStage" should be ran in the same pipeline
next stage should be triggered automatically.
测试变得更加可读,测试意图也变得更加明显。
作为Developer的特质之一就是细节驱动,我们将各种业务需求整理为更为详细的技术实现,并深陷其中, 造成了即便在完成功能测试的时候也不由自主的使用了经过“翻译”的语言。
特质之二就是记性不好(也许只是我),每天早上的Standup我都得靠着自己的Pair或者备忘录才能想起昨天作了什么。那么上面的测试失败时,我没信心自己会记得
verify "defaultStage" is triggered and wait for completed到底意味着什么?
verify pipeline label of "defaultStage" is "1"
脱下Developer的帽子, 换一顶用户的帽子,来跟自己玩儿Q&A
"我要做什么?"
“login” 并 “rerun stage.”
"然后我必须要了解什么? 对我而言,什么是有价值的信息?"
“newly created "defaultStage" should be ran in the same pipeline”
“next stage should be triggered automatically.”
作为技术实现的:
verify "defaultStage" is triggered and wait for completed是系统中的易变部分,随着系统的演化, pipeline label的格式很可能发生变化(譬如可订制),然而业务价值(newly created "defaultStage" should be ran in the same pipeline)却非常稳定,健忘如我也能立即捡起上下文。
verify pipeline label of "defaultStage" is "1"
带上用户的帽子,就是强迫自己以业务价值为角度进行思考。并将思考形式化,最终变成一种习惯。 而这种习惯将给团队带来更加简练,易读、易于维护的测试。
--
Hu Kai
blog : http://iamhukai.blogspot.com/