tdd with-python-and-django

26
Test Driven Development with Python and Django

Upload: flavia-missi

Post on 19-Jul-2015

589 views

Category:

Software


2 download

TRANSCRIPT

Test Driven Developmentwith Python and Django

Who the F**lavia?

Agenda

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

good code and bad code

undead code

what is TDD?

why TDD?

testing for design

how to TDD?

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

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

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

testing smells

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

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

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)

Tools

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

CI - Continuous Integration

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

Tack så mycket!

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