Java -- debugging -- single-step debugging, assertions, and unit testing

Source: Internet
Author: User

One-step debugging: Mainly viewing the changes in variable content 1. set the breakpoint location and set it to Code 2 that may cause problems. run the program in Debug as Mode 3. f5 --> step into enters the method for internal debugging F6 --> step over Single Line Debugging F7 --> step over ends the current method debugging and returns to the method caller for internal debugging assertions: run the program add (int x, int y) www.2cto.com assertion in the Run as mode, which indicates that the condition must be true. When the condition fails, assret ret = 4 is prompted; assertion is disabled by default. The default value is-da. To enable assertion, you only need to pass the-ea parameter to the virtual machine. If the assertion fails, the content on the right of the colon is automatically output. asseret ret = 4: "output content"; unit test: Debug one or more objects. create a JUnit Test Case 2. add the corresponding Test method. JUint uses the method label to determine the method to be called. @ Before indicates the method called Before the Test. For initialization, @ Test indicates that the method is a Test method and there can be multiple, test parameters of different methods in the Test object are used to Test whether the specified conditions meet @ Test (timeout = 1) during the Test. The maximum execution time of the method is 1 millisecond, timeout indicates the method execution error @ Test (specified Ted = NullPointerException. class) determines whether the method has thrown a change exception. If it is thrown, the debugging result is correct. The opposite error @ After indicates that the method is called After the end of the guess, which is generally used for cleaning.

Related Article

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.