Page 1 of 1
assertEquals(real, expected) or...
Posted: Sat Jan 20, 2007 5:09 pm
by Ambush Commander
I personally use the former, but I can't remember which is "right".
Posted: Sat Jan 20, 2007 7:00 pm
by feyd
From taking a quick look in the code, both are right. Maybe you're referring to the error? By default the error is passed through
sprintf() using the second argument it would appear.
Posted: Sat Jan 20, 2007 7:13 pm
by Ambush Commander
Yeah, they use the ambiguous "first" and "second" variable names. Not sure what the error has to do with it.
Posted: Sat Jan 20, 2007 7:35 pm
by aaronhall
I think he's just referring to the order of arguments, feyd.
Posted: Sat Jan 20, 2007 7:58 pm
by Ollie Saunders
I actually mentioned this to lastcraft. I would definitely prefer proper actual, expected parameters, not least because you actually know what is at fault when a test fails that way (as long as the failure messages indicate which is which too).
Posted: Sat Jan 20, 2007 8:23 pm
by feyd
Well, by default the error string is "%s." In the code, the call is passed to an assert method which receives an expectation object and a comparison. Sprintf() is passed the results from a method of the expectation class called overlayMessage(). In turn, testMessage() is called for the expectation class. From assert() on forward, the $second argument has been renamed $compare.
The reason why I asked if you were talking more of the error is that value is what will be printed when it fails.
Posted: Sat Jan 20, 2007 8:24 pm
by Ambush Commander
Error = failed assertion then yes. (You've got to be careful because SimpleTest also handles legit errors made with trigger_error)
So... what does $compare mean?
Posted: Sat Jan 20, 2007 8:27 pm
by feyd
The expected result when tested against the expectation.
Posted: Sat Jan 20, 2007 8:28 pm
by Ambush Commander
Ah, so I've got it right.
It should be noted that JsUnit appears to have it reversed.
Posted: Mon Jan 29, 2007 6:56 pm
by lastcraft
Hi.
Actually I think it's me that has it "wrong". SUnit lists expected value first, and that is the fount of all XUnit tools. I went for the more naturally spoken "assert that real equals the expected".
It's interesting that the RSpec tool has as one of it's selling points that with their system you cannot get it wrong. Seems like it's a common problem.
Hopefully the parameter names will change in an upcoming version. I'll add it to my TODO.
yours, Marcus