CARVIEW |
robertpenner / hamcrest-as3 forked from drewbourne/hamcrest-as3
- Source
- Commits
- Network (8)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
-
Branches (1)
- master ✓
- Tags (0)
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
Port of hamcrest to ActionScript 3, a library of matcher objects (also known as constraints or predicates) allowing 'match' rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules. — Read more
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Tue May 12 10:11:33 -0700 2009 | updates to date handling, added tests which use... [jtapper] |
![]() |
README.markdown | Thu Jun 04 09:52:36 -0700 2009 | added LICENSE, reformatted src/ to match Adobe ... [Drew Bourne] |
![]() |
hamcrest-unit-test/ | Thu Jun 11 13:57:09 -0700 2009 | Updated package reference in test runner to use... [robertpenner] |
![]() |
hamcrest/ | Thu Jun 11 13:52:48 -0700 2009 | Removed src-integration path from project setti... [robertpenner] |
Hamcrest for ActionScript 3
Provides a library of matcher objects (also known as constraints or predicates) allowing 'match' rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules.
Description from Hamcrest Project at Google Code
Hamcrest in Tests
Hamcrest is used in combination with a method called assertThat(), providing a mechanism to create composite checks inline, in a simple and clear fashion.
[Test]
public function shouldDemonstrateHamcrestInTests():void {
var values:Array = [1, 2, 3, 4];
assertThat(values, allOf(hasItem(equalTo(3)), hasItem(closeTo(5, 1)));
// should pass
}
The major advantage of using assertThat() and the Hamcrest matchers over traditional assertions such as assertTrue(), assertEquals() is the descriptive failure messages when a matcher (or combination of matchers) does not match succesfully.
[Test]
public function shouldDemonstrateHamcrestDescriptions():void {
var badValues:Array = [1, 2, 3, 7, 8, 9];
assertThat(badValues, allOf(hasItem(equalTo(3)), hasItem(closeTo(5, 1)));
// should fail with the message:
// Expected: (an Array containing <3> and an Array containing a Number within <1> of <5>)
// but: was <7> differed by <2>
}
Hamcrest for MXML
Most of the Matchers have also been made usable in the Flex MXML context by wrapping them in a facade that collects and proxies the Matcher arguments. The declarative format of MXML allows the Matchers to be composed, used and bound to.
<core:AllOf id="numberMatcher" target="{ Number(numberInput.text) }">
<object:NotNull />
<core:AnyOf>
<object:EqualTo value="17" />
<number:CloseTo value="11" delta="0.3" />
<number:Between min="1" max="9" />
</core:AnyOf>
</core:AllOf>
<mx:TextInput id="numberInput" />
<mx:Label text={ numberMatcher.description }"" />
<mx:Label text={ numberMatcher.mismatchDescription }"" />
<mx:Label text={ numberMatcher.matched }"" />