Created
February 2, 2012 22:35
-
-
Save drewbourne/1726229 to your computer and use it in GitHub Desktop.
FlexUnit Parameterized Test with Mockolate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flexunit.example.parameterized | |
{ | |
public class Model | |
{ | |
public function calculate(... args):Number | |
{ | |
return NaN; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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