简体   繁体   中英

intelliji or android studio - short cut to create method test case

Is there a short cut to create a test method quickly in IntelliJ? What I want to happen is if I already have a test class called TestClass, then in my Class file if I create a new method I could right click on the new method and click something like 'create test' on the method itself. There is an option available for the class but I can't see it for the method level. Take a look at this photo and you'll see that the option is available for the class(by pressing alt + enter), but I'd like it available for the method also.

在班级

UPDATE : It seems the option might be in IntelliJ but I cannot find this in Android Studio 1.1. When I hit alt+enter on a method in android studio (where the hosting class already has a test case) I get this menu:

在此处输入图片说明

and here is the funny thing in android studio, if I go into the test case class itself then I see an option to create test method within that class. It's just not showing up in the concrete class I need to be tested:

在此处输入图片说明

Android Studio Ctrl + Shift + T或导航->测试。

For MacOS, it is:

Command (or Cmd) ⌘ + Shift + T

Here is one way to achieve this (tested in IntelliJ 14.0.3):

  • Navigate to the method you wish to create a unit test for
  • Hit ALT + ENTER
  • Select Generate Missed Test Methods

After that dialog will be shown, containing all methods in a given class with only the one you invoked the Generate Missed Test Methods action on selected by default. After you hit OK in the dialog a new test method for selected methods will be added to the existing unit test class.

Here is also a screenshot of the dialog:

在此处输入图片说明

Unfortunately, I haven't found the corresponding action in the keymap settings, so this probably can't be bound directly to some custom keyboard shortcut and it's only accessible via the ALT-ENTER menu.

None of these answers worked for me. I had to actually click the item in the menu (the keyboard shortcut opened something else)

在此处输入图片说明

If you want only create a method, the shortcut is:

  1. Command (or Cmd) ⌘ + N
  2. Select Test function
  3. Input the perfect name for your test

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM