Scala Test
Scala Test Installation
Scala IDE for Eclipse
この手順は,多分いらない.
- market placeから取得するScala IDEではScala Test Pluginがはいってないよう
- help -> install new software -> add
- http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site/
- Scala pluginsをチェック (まだincubationのよう), サブチェックリストも全部.
ScalaTest Jar
- build.gradle
dependencies { testCompile group: 'org.scalatest', name: 'scalatest_2.11', version: '2.2.2' }
ScalaTestコード
Eclispe上
非常にハマったが,@RunWith(classOf[JUnitRunner])を付けないと
No Junit tests foundがでる.
- ExampleSpec.scala
package edu.kzk.scalatest import org.scalatest.FlatSpec import org.scalatest.Matchers import scala.collection.mutable.Stack import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) class ExampleSpec extends FlatSpec with Matchers { "A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1) stack.push(2) stack.pop() should be (2) stack.pop() should be (1) } it should "throw NoSuchElementException if an empty stack is popped" in { val emptyStack = new Stack[Int] a [NoSuchElementException] should be thrownBy { emptyStack.pop() } } }
"" shoud ..., "" must ..., it shout ..., it must ..
のようなBDD-styleでテスト可能.
コマンド
$ scala -cp scalatest_2.11-2.2.2.jar org.scalatest.run ExampleSpec