TestCase from myapp.my_funcs import multiply_these_two_numbers class SillyTest(TestCase): def test_multiply_these_two_numbers(self): """ Tests that the function knows how to do math """ self.assertEqual(multiply_these_two_numbers(4,5), 20)
test myapp Creating test database for alias 'default'... . --------------------------------------------------------- Ran 1 test in 0.000s OK Destroying test database for alias 'default'...
TestCase from myapp.my_funcs import multiply_these_two_numbers class SillyTest(TestCase): def test_multiply_these_two_numbers(self): """ Tests that the function knows how to do math """ self.assertEqual(multiply_these_two_numbers(4,5), 20)
manage.py test myapp Creating test database for alias 'default'... . --------------------------------------------------------- Ran 1 test in 0.000s OK Destroying test database for alias 'default'...
up a question """ question_1 = Question(text="How can my team get started?", votes=7) question_1.increment_votes(4) self.assertEquals(question_1.votes, 11) A few examples
question """ question_1 = Question(text="How can my team get started?", votes=7) question_1.increment_votes(4) self.assertEquals(question_1.votes, 11) The Three A’s
question """ question_1 = Question(text="How can my team get started?", votes=7) question_1.increment_votes(4) self.assertEquals(question_1.votes, 11) The Three A’s
question """ question_1 = Question(text="How can my team get started?", votes=7) question_1.increment_votes(4) self.assertEquals(question_1.votes, 11) The Three A’s
question """ question_1 = Question(text="How can my team get started?", votes=7) question_1.increment_votes(4) self.assertEquals(question_1.votes, 11) The Three A’s
can only supply the text of a question """ form = QuestionForm() self.assertEquals(form.fields.keys(), [‘text']) self.assertNotEquals(form.fields.keys(), ['text', 'votes']) A few examples
that POSTing the right data will result in a new question """ response = self.client.post( '/ask/', {'text': 'Is there any more pizza?’} ) self.assertRedirects(response, '/') self.assertEqual( Question.objects.filter( text='Is there any more pizza?’ ).count(), 1 ) A few examples
subprocess class StardateTestCase(unittest.TestCase): def test_stardate(self): """ Test that we return the current stardate """ output = subprocess.check_output('stardate', shell=True) self.assertEqual(output, '93705.51') if __name__ == '__main__': unittest.main() TDD a CLI
command not found E ================================================================= ERROR: test_stardate (__main__.StardateTestCase) Test that we return the current stardate ----------------------------------------------------------------- Traceback (most recent call last): File "test.py", line 11, in test_stardate output = subprocess.check_output("stardate", shell=True) File "/usr/local/Cellar/python/2.7.10_2/Frameworks/ Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 573, in check_output raise CalledProcessError(retcode, cmd, output=output) CalledProcessError: Command 'stardate' returned non-zero exit status 127 ----------------------------------------------------------------- TDD a CLI
entire project python manage.py test # run all the tests for an app python manage.py test questions # run all the tests in a test case python manage.py test questions.HomePageViewTest # run a single test python manage.py test questions.HomePageViewTest.test_root_url_shows_questions
'django_jenkins', ) ... JENKINS_TASKS = ( 'django_jenkins.tasks.run_pylint', 'django_jenkins.tasks.with_coverage', 'django_jenkins.tasks.django_tests', # there are more of these ) $ python manage.py jenkins # Jenkins will run this command