Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Create a new test case. For information on creating a new test case see Writing a basic test.
  • Import the SimpleRule.as class.
    Code Block
    actionscript
    actionscript
         import rules.SimpleRule;
    
  • Create a new public variable called ruleOne of type SimpleRule. Instantiate the rule. Attach the [Rule] [Metadata ] metadata to this variable. This will instantiate the rule with the class and cause it to run before/after every test depending on your implementation.
    Code Block
    actionscript
    actionscript
         [Rule]
         public var ruleOne:SimpleRule = new SimpleRule();
    
  • Create some simple test cases, add the test to your test suite and run it. You should see your rule handled before and after each test.

...

As has been alluded to at various points, Rules are not exactly re-usable versions of [Before|FlexUnit Metadata#Before ] and [After]. Rather, they are "decorators," or wrappers around any test method plus their associated [Before]s|FlexUnit Metadata#Before] and [After]s. This means that you have a lot of flexibility in their usage. You can, for example, have a Rule that is meant to be interacted with by the test method itself, say, by setting certain properties on the rule or calling certain methods. Or you can have a Rule that continuously captures profiling information in the background while the test runs, sending that information to a LocalConnection() to be captured and parsed by a listener application. Furthermore, since a Rule's apply() method has information on both the test method (the method parameter) and the test case class (the test parameter), you may have your rule interact with or be responsive to these as well. For example, your rule could inspect the metadata on the test method and conditionally apply functionality based on existent metadata information.

...