Start New Discussion within our Software Development Community

in the code from mox example on their page [] where does PersonDao comes from ?

import unittest
import mox

class DaoUnitTest(unittest.TestCase):

  def setUp(self):
    # Create an instance of Mox
    self.person_mocker = mox.Mox()

  def testUsingMox(self):
    # Create a mock PersonDao
    dao = self.person_mocker.CreateMock(PersonDao)

    # Return a value when this method is called

    # Void method

    # Raise an exception when this is called
    dao.DeletePerson(unknown_person).AndRaise(UnknownPersonError('id not found'))

    # Put all mocks created by mox into replay mode

    # Run the test
    ret_pk = dao.InsertPerson(test_person)
    self.assertRaises(UnknownPersonError, dao, unknown_person)

    # Verify all mocks were used as expected, and tests ran properly
    self.assertEquals(test_primary_key, ret_pk)

I guess to mock an object I would have to call unitest.main() how do I proced with it ?

This article has been dead for over six months. Start a new discussion instead.