Case-sensitive assertEquals Assertion in MXUnit

If you use the MXUnit testing framework for ColdFusion, you might have come across this earlier -- the assertEquals assertion is case-insensitive.

This means that if you try and compare a string like 'abs' and 'Abs', assertEquals returns true.

And that is ok in certain cases, but is not ok in many other. I guess it boils down to the fact that at the end of the day, ColdFusion is case-insensitive. A variable called 'firstName' is the treated the same as 'FirstName'.

But enough of that.

So how do you test for case-sensitivity in assertEquals assertion?

First I thought I'd write my own assertion. But then there is a much simpler solution. Simply hash the the two strings that one needs to compare and assert that they are NOT equal.

So rather than:

assertEquals("abs", "Abs")

Use

assertNotEquals(hash("abs"), hash("Abs"))

It works quite nicely.

Do you do it differently?

BTW, there some discussion of this on the MXUnit Google Groups as well.

Comments

David

David wrote on 12/21/09 6:49 AM

I've used that method in the past too to compare two strings based on case.

Another option could be to use Compare.
EG: assertFalse( Compare("one","One") )

That would return a true (non-zero) result and thus fail the test. (asuming you wanted the test to fail!)

Leave a comment

Tell us about yourself
(required field)
(required field)
Comment and preferences
Leave this field empty: