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 ?

Recommended Answers

All 2 Replies

aww man...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.