drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Westin <chriswesti...@gmail.com>
Subject Please don't use assert in unit tests
Date Fri, 01 May 2015 02:50:12 GMT
I had some confusing times this afternoon as I was working through unit
tests to validate the new allocator I've been working on. (Yes,
TopLevelAllocator will be replaced soon; and the new allocator found leaks
that were happening before.)

By default, when running a junit test in my IDE (eclipse, but I'm sure this
is true elsewhere), it gets no JVM arguments. It's possible to create a
test profile that includes JVM arguments, and this is what is required if
you want to supply things like -ea (enable assertions in the JVM).

This afternoon I was fooled by some tests that appeared to work when I ran
them. This was because they checked their results with java assert, instead
of with the org.junit.Assert.assertXXX static functions, and I didn't have
-ea. (Yes, I've fixed this in my current branch, and replaced the asserts
with the appropriate junit assertXXX()s.)

So, don't use assert to check test results (or verify state in helpers) in
unit tests. This can badly mislead someone who's running the tests into
thinking they are working even if they aren't.

And BTW, I also spotted some tests that were using the junit's assertEquals
like this:  assertEquals(true, <boolean-condition>). Just FYI, for things
like this, you can use assertTrue(<boolean-condition>). There's also an
assertFalse(). Check the javadoc if you need something beyond
assertEquals() -- there are other options.

"Thank you for observing all safety precautions."
Chris

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message