QA/Execution/Web Testing/Docs/Automation/StyleGuide: Difference between revisions

Undo revision 1105014 by Jlorenzo (talk) - I edited the wrong page
No edit summary
(Undo revision 1105014 by Jlorenzo (talk) - I edited the wrong page)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The goal of the style guide is to try provide rules to write code that looks the same no matter what project. It is a guide and is always up for discussion by the team. We have created [https://github.com/mozilla/mozwebqa-test-templates templates] based on the details below.
The goal of the style guide is to try provide rules to write code that looks the same no matter what project. It is a guide and is always up for discussion by the team.


= All Files =
= All Files =
Line 180: Line 180:
def test_advanced_search(self, mozwebqa):
def test_advanced_search(self, mozwebqa):
</source>
</source>
== Assertions ==


* Tests should handle the asserts -- not the page objects.
* Tests should handle the asserts -- not the page objects.
* Tests should use Python's native [https://docs.python.org/2/reference/simple_stmts.html#the-assert-statement assert] statement.
** Note that this is a change from our previous standard of using the [https://wiki.mozilla.org/Web_Testing/Automation/UnittestZero UnittestZero] package.
* When doing equivalency assertions, put the expected value first, followed by the actual value, for example:
<source lang="python">
assert 'expected' == 'actual'  # good
assert 'actual' == 'expected'  # bad
</source>
* When doing negative equivalency, use != and put the unexpected value first, followed by the actual value, for example:
<source lang="python">
assert 'unexpected' != 'actual'  # good
assert 'actual' != 'unexpected'  # bad
</source>
* To directly cause a test to fail raise an AssertionError with an appropriate message, for example:
<source lang="python">
raise AssertionError('message')
</source>
* See [http://pytest.org/latest/assert.html pytest's documentation on asserts] for more help.


= Size of patches =
= Size of patches =
Confirmed users
213

edits