Hi Shannon,
We don't have any explicit documentation regarding setUp() and tearDown
(). This is probably an assumption and omission on our part, as setUp
() and tearDown() are defacto xUnit methods and behave the same way
(basically) from JUnit to pyUnit and others.
Your understanding is correct with resepect to how setUp() and tearDown
() are called. Personally, I view these more as events associated with
running a test. So, MXUnit first instantiates a TestCase, then setUp()
is called, your test method, then tearDown(). This happens for each
test in your test case. setUp() is empty in TestCase so you are
expected to override these methods if you intend to use them.
Otherwise they can safely be omitted and have no impact on your test
(other than a nominal performance hit, adding an empty operation).
The whole idea behind this is that you want your object under test to
be in a known state when testing it. So, setUp() will typically
initialize the object and tearDown() will clean it up, as the test may
have altered the object's state. Example:
function setUp(){
bill = createObject('component','User').init();
bill.setName('Bill');
bill.setEmail('
bi...@mxunit.org');
}
... run test
function tearDown(){
bill = '';
}
I'm not sure what you mean by factor out setUp() and tearDown() for a
test suite. Do you want setUp and tearDown not to run at certain
times? Or maybe you want more control on how your object's state is
maintained at the suite level?
best,
bill