在 Play 中声明测试依赖!
有没有办法在 Play! 的 dependency.yml 文件中声明测试依赖项?框架?我在文档中没有看到任何有关测试依赖项的信息。
例如,我可能想使用 Mockito 等测试库,但由于显而易见的原因,我没有在生产中使用它的类。
Is there a way to declare a test dependency in the dependencies.yml file for the Play! Framework? I don't see any information about test dependencies in the documentation.
For example, I may want to use a testing library such as Mockito but not have its classes used in production for obvious reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您可以定义每个 Play 框架 ID 的依赖项,类似于您可以在 application.conf 文件中定义特定 ID 的设置。为此,您需要在依赖项定义中添加一个额外的
id
属性。例如,如果您只想在框架 ID 为
test
的环境中包含mockito-core,则您的 dependency.yml 文件将如下所示:您可以在使用单台机器时使其工作同样,尽管你必须更加谨慎一些。要测试仅测试依赖项,您需要使用
id: test
定义依赖项,然后运行:然后,要切换回生产,您需要运行:
缺点是您必须请记住每次在测试和生产模式之间切换时同步您的依赖项,但我认为如果您想确保在测试模式下依赖项仅位于类路径上,那么这是目前您可以做的最好的事情。
It seems that you can define dependencies per Play framework ID, similar to how you can define settings for a specific ID in the application.conf file. To do this, you need to add an additional
id
attribute to your dependency definition.For example, if you wanted to only include mockito-core in environments with a framework ID of
test
, your dependencies.yml file would look like the following:You can get this to work when using a single machine as well, although you have to be a bit more deliberate about it. To test with your test-only dependencies, you'd define your dependency with
id: test
and then run:Then, to switch back to production, you'd run:
The downside is that you have to remember to sync your dependencies every time you switch between test and production modes, but I think that this is currently the best you can do if you want to make sure that the dependency is only on the classpath when in test mode.