|
Re: ScalaTest 0.9 Released
|
Posted: Jan 16, 2008 7:31 AM
|
|
> You're welcome. Although I said I'm accustomed to > putting an "expected" value on the left and an "actual" > value on the right, I do prefer Python's system of having > assertEqual(first, second) produce > first != second upon failure. > > For example, if I invent some sort of color > class which considers similar colors equal, I want to > write some tests which have no notion of "expected" and > "actual." I would like assert(navy_blue === > midnight_blue) to pass--and I would like > assert(grape === salmon) to fail with a > message such as grape does not equal salmon .
Except we usually have an expression rather than a literal, so we'd have something like assert(foodType() == salmon) and then we end up looking at "grapes != salmon" and say "Where did 'grapes' come from?" If the test output isn't right next to your code, you have to hunt back to the code to figure out what's up.
> My math brain thinks of equality as symmetric. Therefore, > I find an asymmetric failure message such as > expected this but got that a bit disturbing.
Yes, and frankly, I think that the assertEquals nomenclature from JUnit was a mistake. Equality isn't what the assertion is about, it's about testing an actual given an expectation and it should've been named that way, with a name that indicated its asymmetry.
It's easy to say that all of these stuff doesn't matter, but it does. Good affordances eliminate a lot of confusion. If you can eliminate confusion with a good name, why not?
|
|