使测试代码可用于依赖项目

使测试代码可用于依赖项目

本文介绍了多项目中的 SBT 测试依赖:使测试代码可用于依赖项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SBT 多项目,其中一些项目相互依赖.像这样:

I've a SBT multi-project where some projects have dependencies to each other. Like this:

 lazy val coreProject: Project = Project(
    id = "core-project",
    base = file("./core-project"),
    // other stuff
    ))

  lazy val extensions: Project = Project(
    id = "extensions",
    base = file("./extensions"),
    dependencies = Seq(coreProject)
  )

现在我在 test-folder 的核心"项目中有一些测试代码.还有模拟和测试实用程序之类的东西.现在我想在扩展测试中使用这些测试实用程序.对于生产代码,这是有效的,因为我已经声明了一个依赖项.然而,依赖似乎不适用于测试.当我运行测试时,我收到缺少类的编译错误.这些类来自核心项目中的测试代码.

Now I have some test-code in the 'core' project in the test-folder. There are also stuff like mocks and test-utilities. Now I would like to use those test utilities in the tests of the extensions. For production code this works, since I've declared a dependency. However it seems that dependency doesn't hold for the tests. When I run the tests I get compilation error for missing classes. Those classes are from the test-code in the core-project.

我如何告诉 sbt 依赖项还应该包含测试范围的测试代码?以便我可以在扩展"项目的测试代码中重用我的模拟?

How can I tell sbt that the dependency also should include the test-code for the test-scope? So that I can reuse my mocks in the test-code of the 'exension'-project?

推荐答案

像这样:

dependencies = Seq(coreProject % "compile->compile;test->test")

这在 Getting-启动多项目指南.

这篇关于多项目中的 SBT 测试依赖:使测试代码可用于依赖项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:45