A TestCase is a collection of [TestMethods|FlexUnit TestMethod] that share a common test environment. When using FlexUnit4, each *TestCase* has a {{[\ Wiki Markup [Before
\]
|FlexUnit Before]}} and {{[\[After
\]
|FlexUnit After]}} metadata tags that can be used to decorate methods you want to run before and/or after each test method. These metadatas simulate the {{setUp()
}} and {{tearDown()
}} methods of fluint and FlexUnit .9. So, for example, if you wanted to write a series of [ [TestMethods|FlexUnit TestMethod] ] to test the Flex Timer class, they could all exist in a single TestCase. In the method decorated with {{\[Before
\]
}} you would create a Timer instance to test use in your tests. In the method decorated with {{\[After
\]
}}, you would stop that timer and remove references so it can be garbage collected.
Additionally, you may decorate any number of static methods per class with the medatadata {{[\[BeforeClass
\]
|FlexUnit BeforeClass]}} and {{[\[AfterClass
\]
|FlexUnit AfterClass]}}. These methods will be run once per test class.
An example TestCase
Code Block | ||||
---|---|---|---|---|
| ||||
package sampleSuite.tests { import org.flexunit.Assert; public class TestCase1 { [Before] public function setUp():void { } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test( description="This tests addition" )] public function simpleAdd() : void { var x:int = 5 + 3; Assert.assertEquals( 8, x ); } [Test( description="This tests subtraction" )] public function simpleSubtract() : void { var x:int = 5 - 3; Assert.assertEquals( 2, x ); } } } |