是否可以在Intellij Idea中更改junit4 test的默认类名模板? [英] Is it possible to change default class name template for junit4 test in Intellij Idea?
问题描述
我们的测试类有一个名称约定:
单元测试:TestMyCoolClazz
对于集成测试:ITestMyCoolClazz
但每当Intellij Idea提示创建测试对话框时窗口,类名始终是MyCoolClazzTest。所以基本上它在类和名称上添加了一个单词'Test'。
那么可以改变吗?
使用
有一行:
#set($ testClass =$ {entry.className} Test )
您可以将其更改为,例如:
#set($ testClass =Test $ {entry.className})
或 #set($ testClass =ITest $ {entry.className})
就是这样。我还注意到需要IntelliJ重启。
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?
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:
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.
这篇关于是否可以在Intellij Idea中更改junit4 test的默认类名模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!