Search code examples
intellij-idea

How to customize creation of unit tests in IntelliJ?


I like IntelliJ's unit test creation capability, which can generate stubbed test methods for each of the methods to be tested. Is it possible to customize the code that is generated? For example, currently IntelliJ will create the following test:

public class MyClassTest {

    @Test public void getVersion() {
    }
}

Is there something I could modify such that it could also add a default constructor call, for example?

public class MyClassTest {

    @Test public void getVersion() {
       MyClass myClass = new MyClass();
    }
}

I am using IntelliJ IDEA Ultimate Edition 2019.1.


Solution

  • It's possible to change Test template in "Settings/Preferences | Editor | File and Code Templates": https://blog.codeleak.pl/2013/07/how-to-customize-code-templates-for.html