ERP5 KM

DiscussionUnitTestWriting

I'd like to write some guides for unit test writing. Please free to extend it as you want.

Sequences

Write some atomic functions with names stepDoingSomething, like this:

   1 def stepExample(self,sequence=None,**kw):
   2   pass

Then in function named test_nn_description sequence them:

   1 def test_01_example(self, quiet=0, run=run_all_test):
   2   if not run: return
   3   sequence_list = SequenceList()
   4   sequence_string = """
   5                     stepExample
   6                     stepExample
   7                     stepExample
   8                     stepExample
   9                     stepExample
  10                     stepExample
  11 """
  12   sequence_list.addSequenceString(sequence_string)
  13   sequence_list.play(self)

Important: Remember that it is not possibile to access some system areas between sequences - one sequence is one full scenario.

Checking

Rule: Never create dicts to check for assertions.

Reason: When something goes wrong, you'll have to run test to understand what is wrong.

Always check for smallest possible problem in check.

Assertions

This is list of found nice assertions:

assert
assertAllowedContentTypes
assertAlmostEquals
assertAttributePortalType
assertCopyErrorUnauth
assertDictsMatch
assertEqual
assertEqualDelta
assertEquals
assertFalse
assertGuard
assertNotEqual
assertNotEquals
assertPRoles
assertPSRaises
assertPolicyAllows
assertPolicyDenies
assertRaises
assertSameSet
assertTrue
assertUserDoesNotExists
assertUserExists
assertValidatorRaises
assertWorkflowTransitionFails

Generated by

[shufla@machine Products]$ find /usr/lib/zope/lib/python/Products/ .\
 -name \*py | xargs egrep -o -h 'assert[a-zA-Z]*' | sort | uniq | sort

Discussion/UnitTestWriting (last edited 2008-01-03 13:48:09 by localhost)

Page
  • Immutable Page
  • Info
  • Attachments
User
Learn about new ERP5 releases,technical articles, events and more.

Subscribe to the monthly ERP5 Newsletter!