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

15,387

Solution 1

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:

enter image description here

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.

Solution 2

Android Studio Ctrl+Shift+T or Navigate->Test.

Solution 3

For MacOS, it is:

Command (or Cmd) ⌘ + Shift + T

Share:
15,387
j2emanue
Author by

j2emanue

A mobile developer of both IOS and Android platforms

Updated on June 06, 2022

Comments

  • j2emanue
    j2emanue about 2 years

    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.

    on the class level

    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:

    enter image description here

    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:

    enter image description here