Last active
October 13, 2015 10:21
-
-
Save beck/5c417fd1672a497540d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from mock import patch, Mock | |
from django.shortcuts import render | |
class Dashboard(object): | |
"""This is the system under test.""" | |
@classmethod | |
def view(cls, request): | |
return render(request, 'dashboard.html') | |
class DashboardView_WhenTestedUsingStubs(unittest.TestCase): | |
@patch('__main__.render') | |
def setUp(self, render): | |
render.return_value = Mock(content='<html>dashboard') | |
self.response = Dashboard.view(request=Mock()) | |
def test_returns_a_response_with_a_rendered_dashboard(self): | |
self.assertEqual(self.response.content, '<html>dashboard') | |
class DashboardView_WhenTestedUsingMocks(unittest.TestCase): | |
@patch('__main__.render') | |
def setUp(self, render): | |
self.request = Mock() | |
self.render = render | |
Dashboard.view(self.request) | |
def test_renders_a_request_with_a_template(self): | |
self.render.assert_called_with(self.request, 'dashboard.html') | |
if __name__ == '__main__': | |
unittest.main() |
I like to have long conversations with myself on github. It is my power.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The paper mentions wrappers for types you don't own, but at some point you have to stop wrapping (or you'd go infinitely deep). That's the boundary. It should be thin. And you want to keep it thin because it should be integration tested.
I say "because it should be integration tested" which sounds like I'm making concessions to my design purely for easier testing, but I use that phrase as short-hand for something that is better designed and therefore easier to test. The better design of thin boundaries being decoupling, particularly from components you don't have control over.