2014/09/30

Django series: Tricks on doing Test Driven Development

Preface

This post will not talk about how to write TDD in django. Instead, it covers how to do this HAPPIER (in my opinion).
In case, you do not know how to do TDD under the django framework, please take a look here.

Tricks

  • How to run test cases?

python manage.py test
  • How to colorize the above output?

Take a look here
Personally I am using the pyrg
  • How to change the TEST RUNNER?

Actually, you can change the test runner of django (EG: nose2) instead of using the default one. Take a look here.
Note that you should write this statement TEST_RUNNER='djnose2.TestRunner' instead of TEST_RUNNER=djnose2.TestRunner in order to make this work.
  • How to capture the output from the running tests (eg: pprint, logging etc) with COLOR?

pyrg -- manage.py test -- -B
The difficulty is how to pass options to your test runner.
The first -- tellspyrg that following (manage.py test -- -B) MUST BE arguments instead of OPTIONS. The second -- tells manage.py the -B MUST BE the ARGUMENT instead of the OPTIONS. Then, you can pass the -B options to your custom test runner (I am using nose2).

沒有留言:

張貼留言