Debian Codegraph @

README.rst

raw
1 ======
2 Behave
3 ======
4
5 .. image:: https://img.shields.io/travis/behave/behave/master.svg
6 :target: https://travis-ci.org/behave/behave
7 :alt: Travis CI Build Status
8
9 .. image:: https://readthedocs.org/projects/behave/badge/?version=latest
10 :target: http://behave.readthedocs.io/en/latest/?badge=latest
11 :alt: Documentation Status
12
13 .. image:: https://img.shields.io/pypi/v/behave.svg
14 :target: https://pypi.python.org/pypi/behave
15 :alt: Latest Version
16
17 .. image:: https://img.shields.io/pypi/dm/behave.svg
18 :target: https://pypi.python.org/pypi/behave
19 :alt: Downloads
20
21 .. image:: https://img.shields.io/pypi/l/behave.svg
22 :target: https://pypi.python.org/pypi/behave/
23 :alt: License
24
25 .. image:: https://badges.gitter.im/Join%20Chat.svg
26 :alt: Join the chat at https://gitter.im/behave/behave
27 :target: https://gitter.im/behave/behave?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
28
29
30 .. |logo| image:: https://raw.github.com/behave/behave/master/docs/_static/behave_logo1.png
31
32 behave is behavior-driven development, Python style.
33
34 |logo|
35
36 Behavior-driven development (or BDD) is an agile software development
37 technique that encourages collaboration between developers, QA and
38 non-technical or business participants in a software project.
39
40 *behave* uses tests written in a natural language style, backed up by Python
41 code.
42
43 First, `install *behave*.`_
44
45
46 Now make a directory called "features/".
47 In that directory create a file called "example.feature" containing:
48
49 .. code-block:: gherkin
50
51 # -- FILE: features/example.feature
52 Feature: Showing off behave
53
54 Scenario: Run a simple test
55 Given we have behave installed
56 When we implement 5 tests
57 Then behave will test them for us!
58
59 Make a new directory called "features/steps/".
60 In that directory create a file called "example_steps.py" containing:
61
62 .. code-block:: python
63
64 # -- FILE: features/steps/example_steps.py
65 from behave import given, when, then, step
66
67 @given('we have behave installed')
68 def step_impl(context):
69 pass
70
71 @when('we implement {number:d} tests')
72 def step_impl(context, number): # -- NOTE: number is converted into integer
73 assert number > 1 or number == 0
74 context.tests_count = number
75
76 @then('behave will test them for us!')
77 def step_impl(context):
78 assert context.failed is False
79 assert context.tests_count >= 0
80
81 Run behave:
82
83 .. code-block:: bash
84
85 $ behave
86 Feature: Showing off behave # features/example.feature:2
87
88 Scenario: Run a simple test # features/example.feature:4
89 Given we have behave installed # features/steps/example_steps.py:4
90 When we implement 5 tests # features/steps/example_steps.py:8
91 Then behave will test them for us! # features/steps/example_steps.py:13
92
93 1 feature passed, 0 failed, 0 skipped
94 1 scenario passed, 0 failed, 0 skipped
95 3 steps passed, 0 failed, 0 skipped, 0 undefined
96
97 Now, continue reading to learn how to get the most out of *behave*. To get started,
98 we recommend the `tutorial`_ and then the `feature testing language`_ and
99 `api`_ references.
100
101
102 .. _`Install *behave*.`: http://pythonhosted.org/behave/install.html
103 .. _`tutorial`: http://pythonhosted.org/behave/tutorial.html#features
104 .. _`feature testing language`: http://pythonhosted.org/behave/gherkin.html
105 .. _`api`: http://pythonhosted.org/behave/api.html
106
107
108 More Information
109 -------------------------------------------------------------------------------
110
111 * `behave documentation`_: `latest edition`_, `stable edition`_, `PDF`_
112 * `behave.example`_: Behave Examples and Tutorials (docs, executable examples).
113 * `changelog`_ (latest changes)
114
115
116 .. _behave documentation: http://behave.readthedocs.io/
117 .. _changelog: https://github.com/behave/behave/blob/master/CHANGES.rst
118 .. _behave.example: https://github.com/behave/behave.example
119
120 .. _`latest edition`: http://behave.readthedocs.io/en/latest/
121 .. _`stable edition`: http://behave.readthedocs.io/en/stable/
122 .. _PDF: https://media.readthedocs.org/pdf/behave/latest/behave.pdf