Skip to content

Instantly share code, notes, and snippets.

@drewbourne
Created February 2, 2012 22:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewbourne/1726229 to your computer and use it in GitHub Desktop.
Save drewbourne/1726229 to your computer and use it in GitHub Desktop.
FlexUnit Parameterized Test with Mockolate
package flexunit.example.parameterized
{
public class Model
{
public function calculate(... args):Number
{
return NaN;
}
}
}
package flexunit.example.parameterized
{
import mockolate.expect;
import mockolate.runner.MockolateRule;
import mockolate.stub;
import org.flexunit.assertThat;
import org.flexunit.runners.Parameterized;
import org.hamcrest.object.equalTo;
Parameterized;
[RunWith("org.flexunit.runners.Parameterized")]
public class ParameterizedExample
{
[Rule]
public var mocks:MockolateRule = new MockolateRule;
[Mock]
public var model:Model;
public static function get data():Array
{
return [
[{ foo: "", bar: 10, expected: Number.POSITIVE_INFINITY }],
[{ foo: "1", bar: 10, expected: 3 }],
[{ foo: "1", bar: 10, expected: 3 }],
[{ foo: "5", bar: 10, expected: 2 }],
[{ foo: "2", bar: 10, expected: 5 }],
[{ foo: "2", bar: 10, expected: 1 }],
[{ foo: "2", bar: 10, expected: 1 }],
];
}
[Test(dataProvider="data")]
public function exampleTest(test:Object):void
{
expect(model.calculate(test.foo, test.bar)).returns(test.expected);
assertThat(model.calculate(test.foo, test.bar), equalTo(test.expected));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment