1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
<html>
<head>
<title>pMock: a mock object library for Python</title>
</head>
<body>
<p>pMock has not been under active development since mid 2004.</p>
<p>For other suitable mocking frameworks see the <a href="http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy#MockTestingTools">Cheescake info on python mock testing tools</a></p>
<h1>pMock</h1>
<p>pMock is a Python module for testing Python code using <a href="http://www.mockobjects.com">mock objects</a>.</p>
<pre>
...
import pmock
...
class InstrumentTest(unittest.TestCase):
def test_low_quality_analysis(self):
analyser_mock = pmock.Mock()
analyser_mock.expects().analyse(pmock.eq("123")).will(pmock.return_value("30"))
instrument = Instrument(analyser_mock)
instrument.insert("sample#123")
self.assert_(instrument.is_low_quality_indicator_on())
analyser_mock.verify()
...
</pre>
<p>Inspired by the Java <a href="http://www.jmock.org">jMock</a> library, pMock makes the writing of unit tests using mock object techniques easier.</p>
The typical sequence of steps in a test involving pMock mock objects are:
<ul>
<li>Mock objects are created with expectations and simple behaviours</li>
<li>Code under test is called with the mock objects</li>
<li>Code state is asserted as in normal unit tests</li>
<li>The mock objects' expectations are verified (basically another assertion)</li>
</ul>
See the <a href="overview.html">overview</a> for an introduction on how to use pMock in your unit tests.
<h2>Requirements</h2>
<ul>
<li>pMock is currently written for versions of Python >= 2.3</li>
<li>pMock is licensed under the same terms as Python</li>
</ul>
<ul>
<li><a href="overview.html">Overview</a> of API</li>
</ul>
<h2>Development</h2>
<p>Bitbucket <a href="https://bitbucket.org/grahamcarlyle/pmock-old/">project page</a></p>
<p>Author: Graham Carlyle (grahamcarlyle at graham carlyle dot com)</p>
</body>
</html>
|