简体   繁体   English

如何从命令行运行Scala + specs2?

[英]How do I run Scala + specs2 from the command line?

I'm a completely newbie Scala programmer, and I have no previous experience with Java; 我是一个全新的Scala程序员,我以前没有Java经验; I come from ruby. 我来自红宝石。 I'm trying to run my first TDD sample program. 我正在尝试运行我的第一个TDD示例程序。 I'm planning something very small, with maybe 5 or 6 tests. 我计划一些非常小的东西,可能有5或6个测试。 I'm trying to use the specs2 lib. 我正在尝试使用specs2 lib。 I have no IDE, I usually program with vim and execute stuff from the command line. 我没有IDE,我通常用vim编程并从命令行执行一些东西。

How do I work with scala & specs2 on my little .scala file from the command line? 如何从命令行使用我的.scala文件中的scala和specs2?

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. 我不知道elipsis( ... )代表什么。 What do I have to put there? 我该怎么办?
  2. That command references (I assume) a file called specs2.run . 该命令引用(我假设)一个名为specs2.run的文件。 But on the downloads section I only get a .jar file. 但在下载部分我只得到一个.jar文件。 Where is specs2.run ? 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). 依赖关系部分,我给出了两种技术 - sbt和maven(我用谷歌搜索过,之前不知道它们)。 Do I have to use sbt/maven no matter what? 无论如何我都必须使用sbt / maven吗? Can't I just use a console command? 我不能只使用控制台命令吗? It's only 1 file with 5 tests. 它只有1个文件,有5个测试。
  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. 我认为它准备好与sbt和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. 非常感谢。

Welcome to scala and specs2! 欢迎来到scala和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). ...代表运行规范所需的所有jar的路径,包括您自己的(或包含.class文件的目录的路径)。 Those jars are listed on the Runners page. 这些罐子列在Runners页面上。 For a simple specification you only need scalaz-core , scalaz-concurrent and specs2 . 对于简单的规范,您只需要scalaz-corescalaz-concurrentspecs2

  2. specs2.run is the full name of the class used to run your specification on the command line. specs2.run是用于在命令行上运行规范的类的全名。 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) 如果你知道在哪里获得所需的jar以及如何编译你的scala类(使用scalac命令),你确实可以在没有sbt或maven的情况下使用命令行

  4. yes, the sample app comes with sbt and maven project files so that running the tests just takes sbt test for example. 是的,示例应用程序带有sbt和maven项目文件,因此运行测试只需要进行sbt test If you do that, sbt installs all the required dependencies, compiles the classes and runs the tests. 如果你这样做,sbt会安装所有必需的依赖项,编译类并运行测试。 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 我认为这是最好的入门方式(遵循sbt 安装指南 ,它真的很快恕我直言)但是再次,对于一个简单的项目,你也可以手动完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM