我如何运行 Scala +来自命令行的spec2?

发布于 2024-12-11 12:59:21 字数 886 浏览 0 评论 0原文

我是一个完全新手的 Scala 程序员,之前没有任何 Java 经验;我来自红宝石。我正在尝试运行我的第一个 TDD 示例程序。我正在计划一些非常小的事情,可能进行 5 或 6 次测试。我正在尝试使用specs2 库。我没有 IDE,我通常使用 vim 编程并从命令行执行东西。

我如何使用 scala &从命令行在我的小 .scala 文件上指定 specs2 ?

快速入门中,他们提到了这一点:

scala -cp ... specs2.run HelloWorldSpec
  1. 我不知道省略号 (...) 代表什么。我必须在那里放什么?
  2. 该命令引用(我假设)一个名为 specs2.run 的文件。但在下载部分我只得到一个 .jar 文件。 specs2.run 在哪里?
  3. 依赖项 部分中,我给出了两种技术 - sbt 和 maven (我用谷歌搜索了它们) ,以前不认识他们)。无论如何我都必须使用 sbt/maven 吗?我不能只使用控制台命令吗?它只有 1 个文件,包含 5 个测试。
  4. 我知道有一个示例应用程序,但它同样没有提供有关如何运行它的说明。我认为它已经准备好与 sbt 和 Maven 一起工作。我宁愿不必学习使用其中任何一个只是为了进行快速测试。是否可以?

多谢。

I'm a completely newbie Scala programmer, and I have no previous experience with Java; I come from ruby. I'm trying to run my first TDD sample program. I'm planning something very small, with maybe 5 or 6 tests. I'm trying to use the specs2 lib. I have no IDE, I usually program with vim and execute stuff from the command line.

How do I work with scala & specs2 on my little .scala file from the command line?

In the Quick Start they mention this:

scala -cp ... specs2.run HelloWorldSpec
  1. I don't have any idea what that elipsis (...) is standing for. What do I have to put there?
  2. That command references (I assume) a file called specs2.run. But on the downloads section I only get a .jar file. Where is specs2.run?
  3. In the dependencies section I'm given between two technologies - sbt and maven (I googled for them, didn't know them before). Do I have to use sbt/maven no matter what? Can't I just use a console command? It's only 1 file with 5 tests.
  4. I'm aware that there is a sample app, but again it comes with no instructions on how to run it. I think it comes prepared to work with sbt and maven. I would rather not have to learn to use any of those just to make a quick test. Is it possible?

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

携余温的黄昏 2024-12-18 12:59:21

欢迎使用 scala 和 specs2!

  1. ... 代表运行规范所需的所有 jar 的路径,包括您自己的(或包含 .class 的目录的路径)文件)。这些 jar 列在 Runners 页面上。对于简单的规范,您只需要 scalaz-corescalaz-concurrentspecs2

  2. specs2.run 是用于在命令行上运行规范的类的全名。因此,运行规范的完整命令如下所示:

    scala -cp scalaz-core.jar:scalaz-concurrent.jar:specs2.jar:你的类目录specs2.run YourSpecification

  3. 如果您知道在哪里获取所需的 jar 以及如何编译 scala 类(使用 scalac 命令)

  4. 是的,示例应用程序附带 sbt 和 maven 项目文件,因此运行测试只需 sbt test 例如。如果这样做,sbt 将安装所有必需的依赖项、编译类并运行测试。我认为这是最好的入门方式(遵循 sbt 安装指南,恕我直言,它真的很快)但是,对于一个简单的项目,您也可以手动执行此操作

Welcome to scala and specs2!

  1. The ... stands for the paths to all the jars you need to run the specifications, including your own (or a path to a directory containing the .class files). Those jars are listed on the Runners page. For a simple specification you only need scalaz-core, scalaz-concurrent and specs2.

  2. specs2.run is the full name of the class used to run your specification on the command line. So, a full command to run a specification looks like:

    scala -cp scalaz-core.jar:scalaz-concurrent.jar:specs2.jar:your-classes-directory specs2.run YourSpecification

  3. You can indeed use the command line only without sbt or maven if you know where to get the jars you need and how to compile your scala classes (using the scalac command)

  4. yes, the sample app comes with sbt and maven project files so that running the tests just takes sbt test for example. If you do that, sbt installs all the required dependencies, compiles the classes and runs the tests. I think that this is the best way to get started (follow the sbt install guide, it's really fast IMHO) but again, for a simple project you can also do that manually

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