Yurii Bondarenko
Yurii Bondarenko

Reputation: 3550

Is it possible to change default class name template for junit4 test in Intellij Idea?

We have a name convention for our test classes:


For unit test : TestMyCoolClazz

For integration tests : ITestMyCoolClazz


But whenever Intellij Idea prompts 'Create Test' dialog window, class name is always MyCoolClazzTest. So basically it adds a word 'Test' at the and of a class name.

So can a change it?

enter image description here

Upvotes: 2

Views: 660

Answers (1)

koto
koto

Reputation: 740

There is a workaround using JUnitGenerator plugin, maybe it will suit your needs. Thing is, it doesn't allow to customize the mentioned 'Create Test' popup invoked by Shift+Ctrl+T, but you can customize the way how IDE generates tests by pressing Alt+Insert and then selecting JUnitTest -> JUnit 3/4.

So if it would be sufficient, there's the way: after installing this plugin, you can find JUnit Generator entry in Settings under the 'Other Settings' section. In a file template window, there is an editable test template, as shown below:

enter image description here

There is a line:

#set( $testClass="${entry.className}Test")

You can change it to, for example:

#set( $testClass="Test${entry.className}") or #set( $testClass="ITest${entry.className}")

and that's it. I also noticed that IntelliJ restart is required.

Upvotes: 1

Related Questions