在 sbt 中将测试类导入 Scala 控制台? [英] Importing test classes into Scala console in sbt?

查看:25
本文介绍了在 sbt 中将测试类导入 Scala 控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sbt 在标准目录布局中构建一个 Scala 项目.我想运行 sbt console 并导入我的单元测试,以便我可以在 Scala REPL 中使用它们.什么是最简单的方法来做到这一点?有没有我可以传递给 sbt 的命令,或者我可以添加到 build.sbt 的东西?

请注意,我不一定要从 sbt 控制台 运行单元测试.(虽然这也很好.)相反,有一个测试装置来设置我想在我的 REPL 会话中使用的数据结构.

解决方案

使用 test 配置范围,像这样:

sbt>测试:控制台

有关详细信息,请参阅 sbt 文档中的范围.>

以 specs2 为例,您可以:

sbt>测试:控制台控制台>导入 mytestpackage._控制台>导入 org.specs2._控制台>specs2.run(新的MySpec)

I am building a Scala project in the standard directory layout using sbt. I want to run sbt console and import my unit tests so that I can play with them in the Scala REPL. What is the easiest way to do this? Is there a command I can pass to sbt, or something I can add to build.sbt?

Note that I don't necessarily want to run unit tests from the sbt console. (Though that would be nice too.) Instead a have test fixtures that set up data structures that I want to use in my REPL session.

解决方案

Use test configuration scope, like this:

sbt> test:console

For more information, see Scopes in the sbt documentation.

With specs2 for example, you can go:

sbt> test:console

console> import mytestpackage._
console> import org.specs2._
console> specs2.run(new MySpec)

这篇关于在 sbt 中将测试类导入 Scala 控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆