我如何运行 Scala +来自命令行的spec2?
我是一个完全新手的 Scala 程序员,之前没有任何 Java 经验;我来自红宝石。我正在尝试运行我的第一个 TDD 示例程序。我正在计划一些非常小的事情,可能进行 5 或 6 次测试。我正在尝试使用specs2 库。我没有 IDE,我通常使用 vim 编程并从命令行执行东西。
我如何使用 scala &从命令行在我的小 .scala 文件上指定 specs2 ?
在快速入门中,他们提到了这一点:
scala -cp ... specs2.run HelloWorldSpec
- 我不知道省略号 (
...
) 代表什么。我必须在那里放什么? - 该命令引用(我假设)一个名为
specs2.run
的文件。但在下载部分我只得到一个 .jar 文件。specs2.run
在哪里? - 在 依赖项 部分中,我给出了两种技术 - sbt 和 maven (我用谷歌搜索了它们) ,以前不认识他们)。无论如何我都必须使用 sbt/maven 吗?我不能只使用控制台命令吗?它只有 1 个文件,包含 5 个测试。
- 我知道有一个示例应用程序,但它同样没有提供有关如何运行它的说明。我认为它已经准备好与 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
- I don't have any idea what that elipsis (
...
) is standing for. What do I have to put there? - That command references (I assume) a file called
specs2.run
. But on the downloads section I only get a .jar file. Where isspecs2.run
? - 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.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎使用 scala 和 specs2!
...
代表运行规范所需的所有 jar 的路径,包括您自己的(或包含.class
的目录的路径)文件)。这些 jar 列在 Runners 页面上。对于简单的规范,您只需要 scalaz-core,scalaz-concurrent 和 specs2。specs2.run
是用于在命令行上运行规范的类的全名。因此,运行规范的完整命令如下所示:scala -cp scalaz-core.jar:scalaz-concurrent.jar:specs2.jar:你的类目录specs2.run YourSpecification
如果您知道在哪里获取所需的 jar 以及如何编译 scala 类(使用
scalac
命令)是的,示例应用程序附带 sbt 和 maven 项目文件,因此运行测试只需
sbt test
例如。如果这样做,sbt 将安装所有必需的依赖项、编译类并运行测试。我认为这是最好的入门方式(遵循 sbt 安装指南,恕我直言,它真的很快)但是,对于一个简单的项目,您也可以手动执行此操作Welcome to scala and specs2!
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.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
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)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