Hey [AsUnit User],
The TestSuite class is extended by the automated "AllTests.as" classes.
Basically, if you load the xml document and store it as a member
variable on a TestCase, it will be destroyed when the TestCase is
destroyed.
The setUp and tearDown methods are called before and after *each*
"test____" method is called within a TestCase, not before *all*
"test___" methods are called.
The TestCase class code to do this might look like what follows:
// Override the run method of TestCase and get your external data
private function run():Void {
// Created a custom class called *ModuleData* that
// extends XML and does the following:
// 1) set the URL TO LOAD = 1st arg in constructor
// 2) set controller = 2nd arg in constructor
// 3) call controller.renderNode(this); when xml is loaded
// Put the instance into a member variable that test functions
// know to look for.
// This object is consumed by members, but not modified by them.
mockData = new ModuleData(mockDataSrc, this);
}
// Have an event handler that gets called when you want the test
// case to execute.
public function renderNode(node:XMLNode):Void {
// call the TestCase run method to begin testing.
super.run();
}
// This will be called BEFORE each method that begins with *test*
public function setUp():Void {
defaultInstance = new Style();
// Pass the XML data to the class under test.
instance = new Style(mockData.firstChild);
mockClip = StyleMockClip(attachMovie(StyleMockClip.linkageId));
}
// This will be called AFTER each method that begins with *test*
public function tearDown():Void {
mockClip.removeMovieClip();
delete defaultInstance;
delete instance;
}
I hope that helps - this has been a HUGE deal for us in how we write
tests. Very often now we use XML documents to configure our test case
so that we don't have a bunch of Magic Numbers or even worse - XML
STRINGS floating around.
Thanks,
Luke Bayes
www.asunit.com
|