如何更改Intellijidea中的Spock测试模板?
从Spock测试生成的位置并有可能在此处添加一些东西可能会很方便。
现在,如果要按(cmd/ctrl)+shift+t ,您可以看到这样的东西
有可能更改基类并生成一些测试方法。但是我该如何添加,例如自动化字符串。
WheelgameCreator target =
我测试的新WheelgameCreator()?
It could be handy to know from where Spock tests are generating and have the possibility to add something there.
For now, if to press (Cmd/Ctrl)+Shift+t you can see something like this
with possibility to change base class and generate some test methods. But how can I add, for example, autogenerated string.
WheelGameCreator target = new WheelGameCreator()
to each my test?
I've found some templates in File and Code Templates, but changes there have no effect on my newly generated tests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“代码”窗格中有Spock测试方法模板
如果您在此处更改模板,则可以在以下方式生成SPOCK测试时使用它:
There is the Spock Test Method template in the "code" pane
In case you change the template here, you may use it when generating the Spock tests in the following way:
我也有同样的问题。从那以后,我发现您设置的模板只有在您浏览
新的... Spock规范上下文菜单(如下)
为了创建一个节目时使用您显示的对话框,您需要编辑Groovy类模板。 (毕竟,Spock规范只是一个凹槽的类)。
值得庆幸的是,在速度模板的帮助下,我能够在此上创建一个条件,以帮助检测它是普通的时髦类还是SPOCK规范。
您可以从中看到,我测试名称以Spec结束(因为这是我用于所有SPOCK规范类的命名约定),如果它确实输出一个模板,否则它将输出不同模板。
您还会注意到我不会导入或扩展规格,因为测试创建将自动执行此操作。
I had the same issue. I have since found that the template that you have set up will only work when you go through the
New... Spock Specification context menu, (like below)
In order to have this show when you create a new test class from the class using the dialog you have shown, you need to edit the groovy class template. (After all, the Spock specification is just a groovy class).
Thankfully, with the help of velocity templates I was able to create a conditional on that, to help detect if it is a normal groovy class or a Spock specification.
You can see from this, I test the name ends with Spec (As that is a naming convention I use for all my Spock Specification classes) and if it does output one template, otherwise it will output a different template.
You will also notice that I don't import, or extend Specification in this as the test creation will do this automatically.