Skip to content

Instantly share code, notes, and snippets.

@yukinagae
Last active August 29, 2015 14:16
Show Gist options
  • Save yukinagae/997435273f3b803b9cd1 to your computer and use it in GitHub Desktop.
Save yukinagae/997435273f3b803b9cd1 to your computer and use it in GitHub Desktop.
【STEP4】テスト : Scalaでコードを書く ref: http://qiita.com/yukinagae/items/038f75e9a1bf17978886
import org.scalatest._
import com.example.Calculate
class AddSpec extends FlatSpec with MustMatchers {
"Calculate" should "addメソッドの 1 + 2 = 3" in {
val calculate = new Calculate()
val result = calculate.add(1, 2)
result must be === 3
}
}
package com.example
class Calculate {
def add(x: Int, y: Int): Int = {
x + y
}
}
cd [プロジェクトのルートディレクトリ]
activator.bat
[info] HelloSpec:
[info] Hello
[info] - should have tests *** FAILED ***
[info] true was not equal to false (HelloSpec.scala:6)
[info] Run completed in 155 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
[info] *** 1 TEST FAILED ***
[error] Failed tests:
[error] HelloSpec
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 2 s, completed 2015/02/24 9:01:00
>
2. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to C:\workspace\minimal-scala\target\scala-2.11\test-classes...
[warn] there were two deprecation warnings; re-run with -deprecation for details
[warn] one warning found
[info] HelloSpec:
[info] Hello
[info] - should have tests
[info] Run completed in 125 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 1 s, completed 2015/02/24 9:02:00
3. Waiting for source changes... (press enter to interrupt)
[info] HelloSpec:
[info] Hello
[info] - should have tests
[info] - should 1 + 1 = 2
[info] Run completed in 141 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 1 s, completed 2015/02/24 9:03:00
4. Waiting for source changes... (press enter to interrupt)
[info] HelloSpec:
[info] Hello
[info] - should have tests
[info] - should 1 + 1 = 2
[info] Run completed in 141 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 1 s, completed 2015/02/24 9:03:00
4. Waiting for source changes... (press enter to interrupt)
./activator
"Hello" should "have tests" in {
true should be === true
}
"Hello" should "have tests" in {
true should be === true
}
true should be === true
[info] HelloSpec:
[info] Hello
[info] - should have tests
[info] Run completed in 203 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 4 s, completed 2015/02/24 9:00:00
>
import org.scalatest._
class HelloSpec extends FlatSpec with MustMatchers {
"Hello" should "have tests" in {
true must be === true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment