[ Level 2 ] Tips of unittest for Python.

There are tips for Python:
1. Use mock for replace method.
ex.
myMock=mox.Mox()
myMock.StubOutWithMock(myModule, 'replaceMethod')
myModule.replaceMethod(input).AndReturn('Hello World!')
myMock.ReplayAll()
expected = 'Hello World!'
self.assertEqual(module.replaceMethod(input), expected)
myMock.VerifyAll()  #verify if all mocks be executed.
myMock.UnsetStubs() #release all mocks

2. Use -m to test one method only.
ex.
$ python -m unittest myApp.TestClass.testMethod

Wish this helps.

regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 1] Rar tool for Solaris.

[Level 2] iif in Python