You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

running-tests.rst 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ==========
  2. Test suite
  3. ==========
  4. Running tests
  5. -------------
  6. Oscar uses a nose_ testrunner which can be invoked using::
  7. $ ./runtests.py
  8. .. _nose: http://nose.readthedocs.org/en/latest/
  9. To run a subset of tests, you can use filesystem or module paths. These two
  10. commands will run the same set of tests::
  11. $ ./runtests.py tests/unit/order
  12. $ ./runtests.py tests.unit.order
  13. To run an individual test class, use one of::
  14. $ ./runtests.py tests/unit/order:TestSuccessfulOrderCreation
  15. $ ./runtests.py tests.unit.order:TestSuccessfulOrderCreation
  16. (Note the ':'.)
  17. To run an individual test, use one of::
  18. $ ./runtests.py tests/unit/order:TestSuccessfulOrderCreation.test_creates_order_and_line_models
  19. $ ./runtests.py tests.unit.order:TestSuccessfulOrderCreation.test_creates_order_and_line_models
  20. Testing against different setups
  21. --------------------------------
  22. To run all tests against multiple versions of Django and Python, use tox_::
  23. $ tox
  24. You need to have all Python interpreters to test against installed on your
  25. system. All other requirements are downloaded automatically.
  26. .. _tox: http://tox.readthedocs.org/en/latest/
  27. Kinds of tests
  28. --------------
  29. Tests are split into 3 folders:
  30. * unit - These are for tests that exercise a single unit of functionality, like
  31. a single model. Ideally, these should not write to the database at all - all
  32. operations should be in memory.
  33. * integration - These are for tests that exercise a collection or chain of
  34. units, like testing a template tag.
  35. * functional - These should be as close to "end-to-end" as possible. Most of
  36. these tests should use WebTest to simulate the behaviour of a user browsing
  37. the site.
  38. Naming tests
  39. ------------
  40. Oscar's testrunner uses the progressive_ plugin when running all tests, but uses
  41. the spec_ plugin when running a subset. It is a good practice to name your test
  42. cases and methods so that the spec output reads well. For example::
  43. $ ./runtests.py tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount
  44. nosetests --verbosity 1 tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount -s -x --with-spec
  45. Creating test database for alias 'default'...
  46. Absolute discount
  47. - consumes all lines for multi item basket cheaper than threshold
  48. - consumes all products for heterogeneous basket
  49. - consumes correct quantity for multi item basket more expensive than threshold
  50. - correctly discounts line
  51. - discount is applied to lines
  52. - gives correct discount for multi item basket cheaper than threshold
  53. - gives correct discount for multi item basket more expensive than threshold
  54. - gives correct discount for multi item basket with max affected items set
  55. - gives correct discount for single item basket cheaper than threshold
  56. - gives correct discount for single item basket equal to threshold
  57. - gives correct discount for single item basket more expensive than threshold
  58. - gives correct discounts when applied multiple times
  59. - gives correct discounts when applied multiple times with condition
  60. - gives no discount for a non discountable product
  61. - gives no discount for an empty basket
  62. ----------------------------------------------------------------------
  63. Ran 15 tests in 0.295s
  64. .. _progressive: http://pypi.python.org/pypi/nose-progressive/
  65. .. _spec: http://darcs.idyll.org/~t/projects/pinocchio/doc/#spec-generate-test-description-from-test-class-method-names