1

What's the difference between these 2 Assert class methods?

3 Answers 3

1

assertEquals will give you more information for example if you compare a and b, it will show which one is bigger. But assertTrue will only show the result, like expected true, found false.

0

It is all about semantic.. Your tests should be logical and readable. If your criterion is boolean, there is no need to use complex constructions. That's much like when you use if.

Instead of if(val == true){} you will likely use if (val){}.

Using assertEquals makes sense when you deal with complex structures.

0

assertEquals is specifically for comparison between two objects (strings, integers or any class objects). Whereas, assertTrue is more generic in the sense that it asserts any condition with boolean value true.

Still, it boils down to semantic from software testing solutions perspective as both can be used in each other's stead. For example, you can do

assertEquals(true, any-boolean-condition), and

assertTrue(object1.equals(object2))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.