Hyper Open Edge Cloud

Unit Test Writing

Guide for unit test writing.
  • Last Update:2016-05-16
  • Version:001
  • Language:en

Guide for unit test writing.

Table of Contents

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
  assertAuth
  assertCatalogRaises
  assertCell
  assertCellIsNone
  assertCopyErrorUnauth
  assertDeclaration
  assertDictsMatch
  assertEqual
  assertEqualDelta
  assertEquals
  assertFalse
  assertFieldInGroup
  assertGuard
  assertHooks
  assertInContext
  assertLogsMessage
  assertMovementExists
  assertNotEqual
  assertNotEquals
  assertPermission
  assertPermissionsOfRole
  assertPolicyAllows
  assertPolicyDenies
  assertPRoles
  assertPSRaises
  assertRaises
  assertRangeMatch
  assertRolesEqual
  assertRolesOfUser
  assertSameSet
  assertSetattrDeclaration
  assertSetattrState
  assertState
  assertTrue
  assertTypeImplements
  assertUE
  assertUnauth
  assertUserCanAccessDocument
  assertUserCanAddDocument
  assertUserCanChangeLocalRoles
  assertUserCanModifyDocument
  assertUserCanPassWorkflowTransition
  assertUserCanViewDocument
  assertUserDoesNotExists
  assertUserExists
  assertUserHavePermissionOnDocument
  assertUserHaveRoleOnDocument
  assertValidatorRaises
  assertWorkflowTransitionFails
  assertXMLViewIsEqual

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

And similarly, failIf:

  failIf
  failIfDifferentSet
  failIfEqual
  failIfLocked
  failIfLogsMessage
  failIfUserCanAccessDocument
  failIfUserCanAddDocument
  failIfUserCanChangeLocalRoles
  failIfUserCanModifyDocument
  failIfUserCanPassWorkflowTransition
  failIfUserCanViewDocument
  failIfUserHavePermissionOnDocument
  failIfUserHaveRoleOnDocument

Related Articles