What is the actual difference between assertEquals() vs assertTrue() in TestNG?

前端 未结 1 1337
终归单人心
终归单人心 2020-12-31 03:21

I\'m confusing about both these methods, because both can do the same thing, like below snippet of my code.

Using assertEquals()

Str         


        
相关标签:
1条回答
  • 2020-12-31 04:00

    assertEquals is better because it gives the unit test framework more information about what you're actually interested in. That allows it to provide better error information when the test fails.

    Suppose you had

    String a = "Hello";
    String b = "Hi";
    

    Then the test failures might look something like:

    // From assertEquals(a, b)
    Error: Expected "Hi"; was "Hello"
    
    // From assertTrue:
    Error: Expected true; was false
    

    Which of those do you think gives you more information, bearing in mind that the values would probably be the result of reasonably complex computations?

    (These are made up error messages as I don't have testng installed, but they're the kind of thing unit test frameworks give.)

    0 讨论(0)
提交回复
热议问题