Modifying JUnit plugin in Android Studio/IDEA

Hello,

I would like to modify the current Android Studio's Generate JUnit dialog. My intentions are the following:

a) change the default class name from MyClassTest to MyClassTests (trivial, I know)
b) I would like to process the attributes of the tested class in a similar fashion as the methods, auto-generating mocks like so:

public class MyClassTest {
  private Dependency mDependency;

  @Before
  public void setup() throws Exception {
    mDependency = mock(Dependency.class);
  }
}

c) optionally generate some code that I usually use in my unit tests like enumerations, initialization methods etc.

I've created new project, simply following the basics steps of developing a new plugin for IDEA and was able to display a basic dialog window upon right clicking an editor window. But eventually I've realized that I don't rediscover the wheel with rewriting the heavy-lifting stuff (Java syntax analyzer, lexer, etc.) and simply want to modify just some of the behavior.

Is it possible to modify the standard JUnit plugin for Android Studio? If so, where can I find the source code?

3 comments
Comment actions Permalink

Hi Marek,

 

did you try to modify corresponding file templates?

 

You can't modify standard junit plugin currently but you may register your own com.intellij.testIntegration.TestFramework which would plug to the same dialog and you'll be able to do there everything you need.

 

Anna

0
Comment actions Permalink

Hi, Anna,

> did you try to modify corresponding file templates?

Sort of. File templates work amazing when I want to add certain code each time (i.e. package imports).


ad a) I don't think that test file name can be modified, or at least I did not find the setting.

ad b, c) So the dialog itself is unmodifiable? I'm not talking about complete overhaul, just adding 1 checkbox and adding class attributes to the member list.

Thank you for you help, it's much appreciated.

Marek

0
Comment actions Permalink

The dialog itself is not pluggable, unfortunately.

0

Please sign in to leave a comment.