harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Qiu <sean.xx....@gmail.com>
Subject Re: Hamcrest
Date Thu, 06 Aug 2009 09:54:25 GMT
If I remember correctly, it is one of the advantage that made us
upgrade our junit from 3.x to 4.4.  :-)
So far, I haven't see anyone make advantage of it, but you can take
the initiate.It is pretty cool~

By the way, seems the upcoming new version of junit will bring another
new interesting feature - Per-Test rules[1].

[1] http://www.infoq.com/news/2009/07/junit-4.7-rules

Best Regards
Sean, Xiao Xia Qiu




2009/8/6 Charles Lee <littlee1032@gmail.com>:
> Great News. I have checked the RELEASE NOTES about junit4.4. It seems has
> already include this hamcrest.
> Here is what it said:
>
> Advantages of this assertion syntax include:
>
>   -
>
>   More readable and typeable: this syntax allows you to think in terms of
>   subject, verb, object (assert "x is 3") rather than assertEquals, which
>   uses verb, object, subject (assert "equals 3 x")
>   -
>
>   Combinations: any matcher statement s can be negated (not(s)), combined (
>   either(s).or(t)), mapped to a collection (each(s)), or used in custom
>   combinations (afterFiveSeconds(s))
>   -
>
>   Readable failure messages. Compare
>
>   assertTrue(responseString.contains("color") ||
> responseString.contains("colour"));
>   // ==> failure message:
>   // java.lang.AssertionError:
>
>
>   assertThat(responseString, anyOf(containsString("color"),
> containsString("colour")));
>   // ==> failure message:
>   // java.lang.AssertionError:
>   // Expected: (a string containing "color" or a string containing "colour")
>   //      got: "Please choose a font"
>
>   -
>
>   Custom Matchers. By implementing the Matcher interface yourself, you can
>   get all of the above benefits for your own custom assertions.
>   -
>
>   For a more thorough description of these points, see Joe Walnes's
>   original post <http://joe.truemesh.com/blog/000511.html>.
>
> Have fun and enjoy it :-)
>
>
> On Thu, Aug 6, 2009 at 4:05 PM, Jimmy,Jing Lv <firepure@gmail.com> wrote:
>
>> Sounds interesting Charles.
>>
>> I guess it should require more dependence on Hamcrest, which may be some
>> extra cost for building and footprint? So would you please describe what
>> the
>> advantages are, and share your experience? Or share us some examples?
>>
>> 2009/8/6 Charles Lee <littlee1032@gmail.com>
>>
>> > Hi guys,
>> >
>> > These days I am writing some testcase to the harmony using Hamcrest. I'd
>> > like to introduce harmcrest to the community :-)
>> >
>> > Hamcrest 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. It maybe the only third-party plugin which junit
>> > supports. Check out these beautiful asserts:
>> > 1. assertThat(object1, equalTo(object2))
>> > 2. assertThat(object1, is(anything()))
>> > 3. assertThat(boolean, allOf(boolean1, boolean2))   (like and)
>> > 4. assertThat(boolean, anyOf(boolean1, boolean2)) (like or)
>> > 5. assertThat(obj1, instanceOf(CLASS))
>> > 6. assertThat(obj1, compatibleTo(CLASS))
>> > .............
>> >
>> > Hamcrest makes unit tests more readable. Besides it speed my unit coding
>> > :-)
>> >
>> > More detail, please visit Hamcrest <http://code.google.com/p/hamcrest/>.
>> >
>> > --
>> > Yours sincerely,
>> > Charles Lee
>> >
>>
>>
>>
>> --
>>
>> Best Regards!
>>
>> Jimmy, Jing Lv
>> China Software Development Lab, IBM
>>
>
>
>
> --
> Yours sincerely,
> Charles Lee
>

Mime
View raw message