LoginSignup
10
8

More than 5 years have passed since last update.

Intellij IDEA 14 + scala + sbt プロジェクトの開始の仕方 + α

Last updated at Posted at 2015-09-05

概要

Intellij 14 で、scala と sbt を利用するプロジェクトを新規で作成するメモ

前提

  • Intelij IDEA Community Edition 14
  • Plugins
    • Scala

手順

  1. Create New Project
  2. Scala -> SBT を選択し、Next
  3. Project name を入力し、Finish

おわり。
 
 
 
 
だとあまりにもなので、
以下、依存に ScalaTest を追加しテストコードを実行するところまで。

テストコードの実施までの作業手順

上記の手順を行った段階で、雛形のディレクトリが出来ていると思います。(Project name には、HelloWorldを指定)

HelloWorld/
  .idea/
  project/
  src/
    main/
      java/
      resources/
      scala/
      scala-2.11/
    test/
      java/
      resources/
      scala/
      scala-2.11/
  target/
  build.sbt

以下、上記のディレクトリ構成を前提として記載していきます。

まずScalaTestを取得

build.sbt に以下の1行を追加

build.sbt
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"

追加した段階で、EnableAutoImport を有効にするか聞かれるので、有効にしました。

External Libraries 配下に、scalatest の jar ファイルが置かれて入れば取得完了です。

ソーソコード作成

src/main/scala/HelloWorld.scala
class HelloWorld {
  def say(name: String) = s"Hello, $name"
}

テストコード作成

src/test/scala/HelloWorldTest.scala
import org.scalatest.FunSuite

class HelloWorldTest extends FunSuite {
  test("Hello, <引数> という文字列が返ってくる") {
    val hello = new HelloWorld
    assert(hello.say("Scala") == "Hello, Scala")
  }
}

実行

テストファイルを副ボタンクリック、Run で実行します。

まとめ

  • plugin 検索に出てくる SBT パッケージなしでも大丈夫だった。
10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8