?????????????頂Test-Driven Development with Python????????????????????????????????????????????(TDD)????????Web??????????????????????????????Щ??????Django??selenium??unittest??????????????????????
??????????????????д?????????????????????д????????????д????????????????д?????????????????У???????????????????????????????????????????TDD????????д????????????д????????????????Щ???
?????????????????????????λ???????TDD?????????·????
??????д?????????????
???????????д?????????????functional_tests.py
????from selenium import webdriver
????browser = webdriver.Firefox()
????browser.get("http://127.0.0.1:8000")
????assert "Django" in browser.title
??????????????????Selenium??д?????????????Firefox?????????????http://127.0.0.1:8000?????assert ?ж????????????????“Django”??
??????????иò?????????
????D:pydj>python functional_tests.py
????Traceback (most recent call last):
????File "functional_tests.py"?? line 6?? in <module>
????assert "Django" in browser.title
????AssertionError
?????????????????????????????????????д????????????????????????????????????????TDD????·???????д?????????????????????
?????????????
??????????????Django?????
????D:pydj>django-admin startproject superlists
???????????????£?
???????? functional_tests.py
???????? superlists
???????? manage.py
???????? superlists
???????? __init__.py
???????? settings.py
???????? urls.py
???????? wsgi.py
???????????????????????
D:pydj> cd superlists
D:pydjsuperlists>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
June 13?? 2016 - 23:23:29
Django version 1.9.7?? using settings 'superlists.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
??????????й????????????functional_tests.py

????????????????д?????????????functional_tests.py
#coding=utf-8
from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.close()
def test_case_start_a_list_and_retrieve_it_later(self):
# С????????????????????????????
# ????????????????
self.browser.get("http://127.0.0.1:8000")
# ?????????????????????“To-Do”???????
self.assertIn("To-Do"?? self.browser.title)
if __name__ == '__main__':
unittest.main()
?????????????unittest ???????????????????Python???????????????????unittest??
??????в?????????
C:Python35python.exe D:/pydj/functional_tests.py
F
======================================================================
FAIL: test_case_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:/pydj/functional_tests.py"?? line 21?? in test_case_start_a_list_and_retrieve_it_later
self.assertIn("To-Do"?? self.browser.title)
AssertionError: 'To-Do' not found in 'Welcome to Django'
----------------------------------------------------------------------
Ran 1 test in 3.491s
FAILED (failures=1)