Summary of Assert methods in JUnit

Source: Internet
Author: User

The Assert methods in JUnit are all placed in the Assert class, summarizing the classification of the Assert methods in the JUnit class.
1. Asserttrue/false([String message,]boolean condition);
Determines whether a condition is true or false. Feel this is the best use, don't write down so many method name.

2.fail([String message,]);
Failed, can have messages, or no messages.

3.assertequals([String message,]object expected,object Actual);
You can specify an output error message if you want to determine equality.
The first parameter is the expected value, and the second argument is the actual one.
This method has multiple implementations for each variable. Basically the same in JDK1.5.
But the idea is to float and double the value of a delta at the back of the number.

4.assertnotequals([String message,]object expected,object Actual);
Determine if they are not equal.
The first parameter is the expected value, and the second argument is the actual one.

5.assertarrayequals([java.lang.String message,] java.lang.object[] expecteds, java.lang.object[] Actuals);

6.assertnotnull/null([String message,]object obj);
Interpret whether an object is non-empty (not empty).

7.assertsame/notsame([String message,]object expected,object Actual);
Determines whether two objects point to the same object. Look at the memory address.

8.failnotsame/failnotequals(String message, object expected, object actual)
Output error messages when they do not point to the same memory address or are not equal.
Note that the information is required, and the output is formatted.

9.assertthat(java.lang.String reason, java.lang.Object actual, Org.hamcrest.Matcher Matcher);

Where reason is the output information when the assertion fails, actual is the asserted value or object, Matcher is the assertion's match, and the logic inside determines that the given actual object is full of unsatisfied assertions.

(if needed is a jar package with assertthat needed to introduce JUNIT4 into the project, as well as Hamcrest-core.jar and Hamcrest-library.jar)

Summary of Assert methods in JUnit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.