The JUnit framework uses (4)--junit common assertions and annotations

Source: Internet
Author: User

Tag: With cells JUnit implementation false dataset exp Core definition

Copy a little something from someone else's blog.

Original address: http://blog.csdn.net/wangpeng047/article/details/9628449

Assertions are the core implementation of writing test cases, that is, what the expected value is, and how much is the result of the test to determine whether the test passed.

Assertion Core Method

See if two arrays are equal.
assertarrayequals (expecteds, actuals)
assertequals (expected, actual) to see if two objects are equal. The Equals () method, similar to string comparisons,
assertnotequals (first, second) to see whether two objects are not equal.
assertnull (object) to see if the object is empty.
assertnotnull (object) to see if the object is not empty.
assertsame (expected, actual) to see whether references to two objects are equal. Similar to using "= =" to compare two objects
assertnotsame (Unexpected, actual) to see whether references to two objects are not equal. Similar to using "! =" to compare two objects
asserttrue (condition) to see if the run result is true.
assertfalse (condition) to see if the run result is false.
assertthat (Actual, matcher) See if the actual value meets the specified condition
fail () let test fail

Annotations

@Before Initialize method
@After Freeing resources
@Test Test method, where you can test for expected exceptions and time-outs
@Ignore Ignored test methods
@BeforeClass For all tests, execute only once and must be static void
@AfterClass For all tests, execute only once and must be static void
@RunWith Specifies that a test class uses a runner
@Parameters To specify a test data collection for a test class
@Rule Allows flexibility to add or redefine the behavior of each test method in a test class
@FixMethodOrder Specify the order in which test methods are executed

A Test class unit test is executed in the following order:

@BeforeClass –> @Before –> @Test –> @After –> @AfterClass

The order in which each test method is called is:

@Before –> @Test –> @After

JUnit Framework uses (4)--junit common assertions and annotations

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.