Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-03 05:54:14 11月23日 Update

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.

Tags: Test statement unit problem logic error method two place actual actually object suggestion situation try prompt run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS Linux vpn Apple