I was reviewing a testcase and came across this construct:
true = NewMeasGap /= MeasGap,
The context is that we want to verify that the MeasGap has changed after we updated a thing that should affect the MeasGap. It’s sufficient to know that it has changed, we don’t need to know the new value.
Is there a better way to express this? MeasGap is a tuple (record).
Yes there is: ?assertNotMatch/2,3 and assertNotEqual/2,3 (from "stdlib/include/assert.hrl") provide much more information if something doesn’t work the way it’s supposed to.
?assertNotMatch/2,3 and ?assertNotEqual/2,3 are the right way to do this, but… if you don’t feel like using macros (or if you don’t like your macros writtenInCamelCase ), this is what I would use with common test:
case NewMeasGap of
MeasGap ->
ct:fail(
"The <what MeasGap represent> should've changed, but it is still ~p",
[MeasGap]);
_ -> cool
end
And… of course… you can put that in a function…
assert_not_match(Value, Value, Meaning) ->
ct:fail("~ts should've changed, but it is still ~p", [Meaning, Value]);
assert_not_match(NewValue, Value, Meaning) -> cool.
…and then…
assert_not_match(MeasGap, NewMeasGap, "The thing")