在 Play 中声明测试依赖!

发布于 2024-11-10 15:35:41 字数 203 浏览 3 评论 0原文

有没有办法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半窗疏影 2024-11-17 15:35:41

看来您可以定义每个 Play 框架 ID 的依赖项,类似于您可以在 application.conf 文件中定义特定 ID 的设置。为此,您需要在依赖项定义中添加一个额外的 id 属性。

例如,如果您只想在框架 ID 为 test 的环境中包含mockito-core,则您的 dependency.yml 文件将如下所示:

require:
    - org.mockito -> mockito-core 1.8.5:
        id: test

您可以在使用单台机器时使其工作同样,尽管你必须更加谨慎一些。要测试仅测试依赖项,您需要使用 id: test 定义依赖项,然后运行:

play dependencies --%test --sync
play test

然后,要切换回生产,您需要运行:

play dependencies --sync
play run

缺点是您必须请记住每次在测试和生产模式之间切换时同步您的依赖项,但我认为如果您想确保在测试模式下依赖项仅位于类路径上,那么这是目前您可以做的最好的事情。

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:

require:
    - org.mockito -> mockito-core 1.8.5:
        id: test

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:

play dependencies --%test --sync
play test

Then, to switch back to production, you'd run:

play dependencies --sync
play 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文