You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Matt Sicker <bo...@gmail.com> on 2014/01/05 09:38:17 UTC

Question/suggestion regarding use of assertions in unit tests.

Hi all, newcomer here. I'm wondering what your opinions are on using
Hamcrest matchers in unit tests. That is, using the assertThat() methods
and the matchers that go with it. It makes many otherwise hard to read
assertions far more literate, plus it provides some nice error messages
explaining why an assertion failed (unlike the native assert keyword and
certain related methods in org.junit.Assert).

I don't know if the tests were migrated from JUnit 3 or anything, but I do
believe it's the preferred way of asserting things in JUnit.

And before anyone says something like "patches welcome", I'd be glad to
help update unit tests for such a thing. :)

-- 
Matt Sicker <bo...@gmail.com>

Re: Question/suggestion regarding use of assertions in unit tests.

Posted by Ralph Goers <rg...@apache.org>.
The tests weren't migrated from junit 3, although I spent many years working with it.  Frankly, until I saw your patch today I was unaware of directly using Hamcrest. Since junit uses it I really have no problem if we do if it makes the tests more readable.

Ralph

> On Jan 5, 2014, at 12:38 AM, Matt Sicker <bo...@gmail.com> wrote:
> 
> Hi all, newcomer here. I'm wondering what your opinions are on using Hamcrest matchers in unit tests. That is, using the assertThat() methods and the matchers that go with it. It makes many otherwise hard to read assertions far more literate, plus it provides some nice error messages explaining why an assertion failed (unlike the native assert keyword and certain related methods in org.junit.Assert).
> 
> I don't know if the tests were migrated from JUnit 3 or anything, but I do believe it's the preferred way of asserting things in JUnit.
> 
> And before anyone says something like "patches welcome", I'd be glad to help update unit tests for such a thing. :)
> 
> -- 
> Matt Sicker <bo...@gmail.com>