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.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/offer/availability_tests.py
  12. $ ./runtests.py tests.unit.offer.availability_tests
  13. To run an individual test class, use one of::
  14. $ ./runtests.py tests/unit/offer/availability_tests.py:TestAPerUserConditionalOffer
  15. $ ./runtests.py tests.unit.offer.availability_tests:TestAPerUserConditionalOffer
  16. (Note the ':'.)
  17. To run an individual test, use one of::
  18. $ ./runtests.py tests/unit/offer/availability_tests.py:TestAPerUserConditionalOffer.test_is_available_with_no_applications
  19. $ ./runtests.py tests.unit.offer.availability_tests:TestAPerUserConditionalOffer.test_is_available_with_no_applications
  20. Testing against different setups
  21. --------------------------------
  22. To run all tests against multiple versions of Django and Python, use detox_::
  23. $ detox
  24. You need to have all Python interpreters to test against installed on your
  25. system. All other requirements are downloaded automatically.
  26. detox_ is a wrapper around tox_, creating the environments and running the tests
  27. in parallel. This greatly speeds up the process.
  28. .. _tox: http://tox.readthedocs.org/en/latest/
  29. .. _detox: https://pypi.python.org/pypi/detox
  30. Kinds of tests
  31. --------------
  32. Tests are split into 3 folders:
  33. * unit - These are for tests that exercise a single unit of functionality, like
  34. a single model. Ideally, these should not write to the database at all - all
  35. operations should be in memory.
  36. * integration - These are for tests that exercise a collection or chain of
  37. units, like testing a template tag.
  38. * functional - These should be as close to "end-to-end" as possible. Most of
  39. these tests should use WebTest to simulate the behaviour of a user browsing
  40. the site.
  41. Naming tests
  42. ------------
  43. When running a subset of tests, Oscar uses the spec_ plugin. It is a good
  44. practice to name your test cases and methods so that the spec output reads well.
  45. For example::
  46. $ ./runtests.py tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount
  47. nosetests --verbosity 1 tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount -s -x --with-spec
  48. Creating test database for alias 'default'...
  49. Absolute discount
  50. - consumes all lines for multi item basket cheaper than threshold
  51. - consumes all products for heterogeneous basket
  52. - consumes correct quantity for multi item basket more expensive than threshold
  53. - correctly discounts line
  54. - discount is applied to lines
  55. - gives correct discount for multi item basket cheaper than threshold
  56. - gives correct discount for multi item basket more expensive than threshold
  57. - gives correct discount for multi item basket with max affected items set
  58. - gives correct discount for single item basket cheaper than threshold
  59. - gives correct discount for single item basket equal to threshold
  60. - gives correct discount for single item basket more expensive than threshold
  61. - gives correct discounts when applied multiple times
  62. - gives correct discounts when applied multiple times with condition
  63. - gives no discount for a non discountable product
  64. - gives no discount for an empty basket
  65. ----------------------------------------------------------------------
  66. Ran 15 tests in 0.295s
  67. .. _spec: https://github.com/bitprophet/spec