html tool

2015年4月28日星期二

BDD_lettuce_before&after

参考地址:http://lettuce.it/reference/terrain.html

------------------------------------------------

@before.all

This hook is ran before lettuce look for and load feature files
The decorated function takes NO parameters
[popexizhi]这个没有参数的应该相对于其他的比较特殊吧!全部feature文件加载前.

@after.all

This hook is ran after lettuce run all features, scenarios and steps
The decorated function takes a TotalResult as parameter, so that you can use the result statistics somehow
from lettuce import *

@after.all
def say_goodbye(total):
    print "Congratulations, %d of %d scenarios passed!" % (
        total.scenarios_ran,
        total.scenarios_passed
    )
    print "Goodbye!
[popexizhi]这里的total应该是一个不错的出report的收集者,回头集成报告可以直接使用了。
---------------------------------------------------------------------------

@before.each_feature

@after.each_feature

[popexizhi]This hook is ran before/after lettuce run each feature
这里的要求参数是feature,下面例子是after的,这个可以看成测试用例集或测试suit吧!
from lettuce import *

@after.each_feature
def teardown_some_feature(feature):
    print "The feature %r just has just ran" % feature.name
-------------------------------------------------------------------------------

@before.each_scenario

@after.each_scenario

[popexizhi]This hook is ran before/after lettuce run each scenario.
感觉lettuce给了很充分的插槽处理位置,可以针对不同位置,一类位置的处理
from lettuce import *
from fixtures import populate_test_database

@before.each_scenario
def setup_some_scenario(scenario):
    populate_test_database()
-----------------------------------------------------------------------------------

@before.each_step

This hook is ran before lettuce run each step
The decorated function takes a Step as parameter, so that you can use it to fetch tables and so.

@after.each_step

This hooks behaves in the same way @before.each_step does, except by the fact that its ran after lettuce run the step.
from lettuce import *

@before.each_step
def setup_some_step(step):
    print "running step %r, defined at %s" % (
        step.sentence,
        step.defined_at.file
    )

[popexizhi] next看一下

django-specific hooks

Since lettuce officially supports Django, there are a few specific hooks that help on setting up your test suite on it.

@before.harvest

感觉lettuce的锚点定义好丰富啊,eg之后再来总结吧!





没有评论:

发表评论