This assumes you have setup your environment as described in [run_tests.md] and that you are in your virtualenv.
-
Take a look at the code in
catinabox/catgenerator.pyand think about how you would write unit tests for it. There's a lot going on in that one method isn't there!Think about the mocks you would need, and what test cases you would cover.
-
Refactor
cat_generatorto be more unit testable:- What responsibilities does
cat_generatorhave? - Can you break
cat_generatorinto several methods, each of which does only one thing?
- What responsibilities does
-
Write unit tests for the refactored
catinabox/catgenerator.pyintests/test_catgenerator.py. Try to get as much coverage as possible. -
As you refactor and write new tests, run them:
(catpy)user@host:~/catinabox$ python setup.py test- When the tests run successfully, push them to your pull request:
(catpy)user@host:~/catinabox$ git commit -a
(catpy)user@host:~/catinabox$ git push origin masterIf you finish writing tests for your refactored code, make a copy of the
original catgenerator.py and write unit tests for it. Compare theses tests
with the tests for the refactored version. What are benefits and drawbacks
of each? How many tests cases do you need in each case?
