Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between the assertTrue method and the assertEquals method of Assert in junit jar package

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Problems encountered in unit testing:

1. AssertEquals (true, check.isSatisfied (data, "4", null, null)

2. Assert.assertTrue (check.isSatisfied (data, "4", null, null)

Both statements can be run correctly if the class under test has no logic errors, but if the class under test has logic errors or other problems, it cannot return true correctly:

1. The first sentence is a good hint.

"expected: but was:"

two。 But the second statement only gives AssertionFailedError:null

It is easy to misunderstand that there is a null value in the object of the written unit test case, but no null value is found; in fact, there is a problem with the tested class.

It is recommended to do a good job with the first statement for unit test, junit4 new assertThat method, you can also try to use.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report