Top Banner
Test Driven Development with Python and Django
26
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tdd with-python-and-django

Test Driven Developmentwith Python and Django

Page 2: Tdd with-python-and-django

Who the F**lavia?

Page 3: Tdd with-python-and-django

Agenda

1. Good code and bad code2. What is TDD?3. Why TDD?4. How to TDD?5. Continuous Integration

Page 4: Tdd with-python-and-django

good code and bad code

Page 5: Tdd with-python-and-django
Page 6: Tdd with-python-and-django

undead code

Page 7: Tdd with-python-and-django

what is TDD?

Page 8: Tdd with-python-and-django
Page 9: Tdd with-python-and-django

why TDD?

Page 10: Tdd with-python-and-django
Page 11: Tdd with-python-and-django

testing for design

Page 12: Tdd with-python-and-django
Page 13: Tdd with-python-and-django
Page 14: Tdd with-python-and-django

how to TDD?

Page 15: Tdd with-python-and-django
Page 16: Tdd with-python-and-django

“You are not allowed to write any production code unless it is to make a failing test pass.”

Page 17: Tdd with-python-and-django

“You are not allowed to write any more of a test than is sufficient to fail; and compilation failures are failures.”

Page 18: Tdd with-python-and-django

“You are not allowed to write any more production code than is sufficient to pass the one failing test.”

Page 19: Tdd with-python-and-django

testing smells

Page 20: Tdd with-python-and-django

def test_should_request_and_be_success(self): response = self.client.get(“/posts”) self.assertEqual(200, response.status_code)

Page 21: Tdd with-python-and-django

def test_should_have_posts_on_ctx(self): response = self.client.get(“/posts”) self.assertIn(“posts”, response.context_data)

Page 22: Tdd with-python-and-django

def test_should_list_posts_in_chronological_order(self): r = self.client.get(“/posts”) expected_posts = [p1, p2, p3, p4] # keep the order self.assertQuerySetEqual(r.context_data[“posts”], expected_posts)

Page 23: Tdd with-python-and-django

Tools

● unittest● django.test.TestCase● nose● py.test● ...

Page 24: Tdd with-python-and-django

CI - Continuous Integration

● drone.io● travisci● circleci● jenkins● hudson● ...

Page 25: Tdd with-python-and-django

Tack så mycket!

Flavia Missi@flaviamissihttps://github.com/flaviamissi