Efficient shortcut keys, debugging, and JUnit in eclipse

Source: Internet
Author: User
Tags assert

Efficient shortcut keys in eclipse

When I learned about the use of these shortcuts, I felt really excited, and I didn't think there were so many amazing features in eclipse that really improved efficiency.

  • Content Tip alt+/
    Content hints for entering a standard library or keyword

  • Quick Fix ctrl+1
    When the editor displays errors, do not want to, first press ctrl+1 for quick fix

  • Guide Pack Ctrl+shift+o
    The shortcut can be used for quick guide, for example, to use the collection class, but not before the corresponding package, you can use the shortcut key

  • Format code block ctrl+shift+f

  • View ALT + forward and backward arrow keys
    This function is useful when debugging code or viewing source code.

  • Add Comment ctrl+shift+/

  • Remove Annotations Ctrl+shift+\

  • View method Description F2

  • Up and down copy row ctrl+alt+ up and down keys
    Can be used to copy up and down the line where the cursor is located

  • Move row up and down ALT + up and down keys
    Can be used to move up or down the row of the cursor

  • View the inheritance relationship for a class ctrl+t
    This method is used to view the inheritance tree of a specified class, especially when the learning framework is viewing the source code.

  • View Source Code Ctrl+shift+t
    Enter the source code to view in the pop-up box open type

  • View shortcut key Settings ctrl+shift+l
    See all the shortcuts in eclipse

Set to view source code under Eclipse

Press CTRL + LEFT mouse button Click to see the standard class library, but if not properly configured, there will be an error
The workaround steps are as follows:

  • Click (window)--"Java"--Installed JRE ("Installed JREs")
  • At this point the list box on the right shows the JRE environment in the system, you can make your own JRE, then click Edit, and the edit window appears.
  • Select the Rt.jar file: ". \jre\lib\rt.jar "and unfold it
  • Expand to see "Source Code Connection: (None)" or "Attachment: (None)", double-click the item, select "Src.zip" file under your JDK directory
  • Identify and complete the configuration
Debugging Debug
  • skip step in F5
  • Skip step Over, F6
  • jump out of step out, F7
  • drag and drop into frame drop to frame
    go to the first line of the current debugging method, this method is more practical, with At debug time the current step skips and goes back
  • jumps to the next breakpoint resume->f8

View breakpoints in a breakpoint (breakpoints) view or clear all breakpoints

The JUnit test framework is basically used
  1. Write a new test class file
  2. Add annotations to the test methods you write @Test
  3. Right-click the method you want to test in the outline (Outline) view, run the configuration (running as), run the method
  4. If you want to test all the methods in a class, you can click on the class to test

For example, to test a class

public class Person {    public void run()    {        System.out.println("run!!");    }    public void eat()    {        System.out.println("eat!!");    }}

where the test class is as follows

import org.junit.Test;//Person的测试类public class PersonTest {    @Test    public void testRun(){        Person p = new Person();        p.run();    }    @Test    public void testEat(){        Person p = new Person();        p.eat();    }}
Special methods for testing classes @before, @After
import org.junit.after;import org.junit.before;import Org.junit.test;//person test class public class    persontest {private person p;        @Before public void before () {System.out.println ("before");    p = new person ();    } @Test public void TestRun () {p.run ();    } @Test public void Testeat () {p.eat ();    } @After public void after () {System.out.println ("after"); }}

Here Add the @before, @After two special methods, both methods run in each method when running, its purpose is to write the initialization of the resources to @before, the release of resources to write the operation @after .
The printed result is
Before
eat!!
After
Before
run!!
After

@BeforeClass, @AfterClass

The two methods are designed when class loads and classes are released.
Note that the method of labeling here must be a static method.

Assert assert
Assert.assertEquals("2",p.run());

If this method does not meet the expectations, then the test does not pass.

Reprint please indicate the author Jason Ding and its provenance
GitHub home page (http://jasonding1354.github.io/)
CSDN Blog (http://blog.csdn.net/jasonding1354)
Jane Book homepage (http://www.jianshu.com/users/2bd9b48f6ea8/latest_articles)

Efficient shortcut keys, debugging, and JUnit in eclipse

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.