Added code snippet in chap2.md for unittest module implementation
This commit is contained in:
parent
4c74e6705e
commit
b97d332ffd
@ -9,7 +9,7 @@ We are trying to build to-do list Django web app
|
||||
* Tends to track *User Story*
|
||||
* **Functional Test** == **Acceptance Test** == **End-to-End Test**
|
||||
|
||||
Steps to create a FT for a MVP/A:
|
||||
Steps to create a FT for a MVP/A (Minimum Viable Product/App):
|
||||
|
||||
1. Prepare a User Story (e.g. user story for to-do list)
|
||||
2. Add test assertions along user story, which is *expected fail*
|
||||
@ -23,6 +23,8 @@ python's default `assert` isn't helpful.
|
||||
|
||||
`unittest` module of python standard library can be used
|
||||
|
||||
Following are highlights of code snippet shown below:
|
||||
|
||||
* tests can be organized into classes, which inherit from `unittest.TestCase`
|
||||
* `setUp` and `tearDown` are special methods that will be run before/after each test, even test failed
|
||||
* main body of tests is in `test_can_start_a_list_and_retrieve_it_later`.
|
||||
@ -31,6 +33,24 @@ python's default `assert` isn't helpful.
|
||||
* Use `self.assertIn()` instead of `assert`. More helper functions like `assertEqual`, `assertTrue`, and `assertFalse` are available in *unittest*
|
||||
* `warning='ignore'` suppresses a superfluous `ResourceWarning`.
|
||||
|
||||
```python
|
||||
class NewVisitorTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.browser = webdriver.Firefox()
|
||||
|
||||
def tearDown(self):
|
||||
self.browser.quit()
|
||||
|
||||
def test_can_start_a_list_and_retrieve_it_later(self):
|
||||
...
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(warnings='ignore')
|
||||
|
||||
|
||||
```
|
||||
|
||||
Hence, a full cycle of test can be executed as it
|
||||
|
||||
1. Open Firefox
|
||||
|
Loading…
x
Reference in New Issue
Block a user