6.1 Ensuring Test Isolation in Funcational Tests
parent
3e3cb00013
commit
81069c3f88
|
@ -0,0 +1,41 @@
|
|||
# Chapter 6. Improving Functional Tests: Ensuring Isolation and Removing Voodoo Sleeps
|
||||
|
||||
## 6.1 Ensuring Test Isolation in Functional Tests
|
||||
|
||||
* Problem left on scratchpad: Clean up after FT runs
|
||||
* Methods:
|
||||
* 1. In `functional_tests.py` add in codes to delete database
|
||||
* 2. Use class `LiveServerTestCase` (Django 1.4). It will create a test db and start up a dev server for functional tests
|
||||
|
||||
How to use `LiveServerTestCase`:
|
||||
* It's derived from Django's `TestCase` class, so can be run by Django test runner
|
||||
* Django test runner search for all scripts start with `test`
|
||||
|
||||
What to do?:
|
||||
1. Create a `functional_test` directory, i.e. create a *functional_test* app
|
||||
2. rename `functional_test.py` as `tests.py` and move it into `functional_test` directory
|
||||
3. Modify `tests.py` to let it use `LiveServerTestCase` as shown below, and instead of hardcoding visit to localhost port 8000, `LiveserverTestCase` provide attribute `live_server_url`.
|
||||
|
||||
```python
|
||||
class NewVisitorTest(LiveServerTestCase):
|
||||
...
|
||||
|
||||
def test_can_start_a_list_and_retrieve_it_later(self):
|
||||
# Edith has heard about a cool new online to-do app. She goes
|
||||
# to check out its homepage
|
||||
self.browser.get(self.live_server_url)
|
||||
```
|
||||
|
||||
### 6.1.1 Running Just the Unit Tests
|
||||
|
||||
We can specify what we want to run by
|
||||
|
||||
```
|
||||
python manage.py test functional_tests
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
python manage.py test lists
|
||||
```
|
Loading…
Reference in New Issue