Java unit test and breakpoint Test

Source: Internet
Author: User

1 Junit and unit Test JUnit unit tests must target Assert for a certain unit such as @ Test. assertEquals ("", ""); if it is the same, JUnit will pass. Otherwise, the classes that do not pass the breakpoint debugging (debug) + watch variable timely value test cannot have example constructor programs: import org. junit. assert; import org. junit. test; public class JUnit {public static void main (String [] args) {String B = "hiperfect"; System. out. println (B) ;}@ Test public void a () {String aa = null; System. out. println (aa); String expecteds = "1"; String actuals = "1"; Assert. AssertEquals (expecteds, actuals) ;}// breakpoint debugging (especially the parameter watch) is often used in the test. 2. breakpoint testing is familiar to everyone, double-click the line header in the Eclipse Java editing area to get a breakpoint, and the code stops running here. 1. Conditional breakpoint: the code stops running at the breakpoint only when the conditions set by the user are met. Right-click the Breakpoint and select the last "Breakpoint Properties" 2. variable breakpoint: a breakpoint can be used not only in a statement, but also in a variable. It can be stopped when the value of the variable is initialized or the value of the variable changes. Of course, the breakpoint can also be set as a condition, the settings are the same as those described above. 3. method breakpoint: The method breakpoint is used to place the breakpoint at the entrance of the method. The method breakpoint can be used in the JDK source code because the JDK removes the debugging information during compilation, therefore, normal breakpoints cannot be hit, but the method breakpoint is acceptable. You can use this method to view the call stack of the method. 4. change the variable value: the code stops at the breakpoint, but the passed value is incorrect. How can I modify the variable value to ensure that the Code continues the correct process, or is there an abnormal branch that is always inaccessible? Can you change the condition during debugging to see if the abnormal branch code is correct? In the Variables small window of the Debug view, we can see that the value of the mDestJarName variable is "F: \ Study \ eclipsepro \ JarDir \ jarHelp. jar "we can right-click the variable and select" Change Value... "Modify the variable value in the pop-up dialog box. re-debugging: This debugging rollback is not omnipotent. It can only be rolled back in the stack frame of the current thread, that is, it can only be returned to the start of the call of the current thread at most. During rollback, right-click the thread method to be rolled back and select "Drop to Frame" 6. exception breakpoints often encounter some exceptions, and then the program exits. It is difficult to find the place where the exception occurs. Fortunately, you can create an exception breakpoint, if an exception breakpoint such as NullPointException is added, when an exception occurs, the Code stops at the exception. It should be helpful to locate the problem.

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.