apache-flexfunctional-testingflexunit

Setting up functional Tests in Flex


I'm setting up a functional test suite for an application that loads an external configuration file. Right now, I'm using flexunit's addAsync function to load it and then again to test if the contents point to services that exist and can be accessed.

The trouble with this is that having this kind of two (or more) stage method means that I'm running all of my tests in the context of one test with dozens of asserts, which seems like a kind of degenerate way to use the framework, and makes bugs harder to find. Is there a way to have something like an asynchronous setup? Is there another testing framework that handles this better?


Solution

  • Assuming you're using FlexUnit 4, addAsync can be called from a [BeforeClass] method:

    public class TestFixture
    {
        [BeforeClass]
        public static function fixtureSetup() : void
        {
            // This static method will be called once for all the tests
            // You can also use addAsync in here if your setup is asynchronous
            // Any shared state should be stored in static members
        }
    
        [Test]
        public function particular_value_is_configured() : void
        {
            // Shared state can be accessed from any test
            Assert.assertEquals(staticMember.particularValue, "value");
        }
    }
    

    Having said that, testing code that accesses a file is really an integration test. I'm also hardly in a position to argue against using ASMock :)