assertEquals(real, expected) or...

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply

Which convention do you use?

assertEqual(real, expected)
3
75%
assertEqual(expected, real)
1
25%
 
Total votes: 4

User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

assertEquals(real, expected) or...

Post by Ambush Commander »

I personally use the former, but I can't remember which is "right".
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Yeah, they use the ambiguous "first" and "second" variable names. Not sure what the error has to do with it.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I think he's just referring to the order of arguments, feyd.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The expected result when tested against the expectation.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Ah, so I've got it right.

It should be noted that JsUnit appears to have it reversed.
lastcraft
Forum Commoner
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London

Post 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
Post Reply