能否请您告诉我使用“ self.fail,这是一种单元测试的方法”的最佳实践??
我不知道是否应该将self.fail与try-except一起使用。
# django-tdd/functional_test.py
# https://github.com/gkzz/django-tdd/blob/chapter2-feature-unittest/functional_test.py
def test_can_start_a_list_and_retrieve_it_later(self):
LOCAL_HOST_URL = 'http://127.0.0.1:8000/'
self.driver.get(LOCAL_HOST_URL)
# Pattern A (with try-except)
try:
self.assertIn('Django', self.driver.title)
except:
self.fail('fail the test')
# Pattern B (said by "Test-Driven Development with Python")
self.assertIn('Django', self.driver.title)
self.fail('fail the test')