JUnit または ScalaTest でクラスを実行する Scala の機能を使用しようとしています。FeatureSpec の例を取り上げ、JUnitSuite を使用した例と組み合わせました。JUnitSuite と組み合わせると、出力 (コンソール) に Scalatest.FeatureSpec 構造体の given/when/then 出力を生成する際に問題が発生します。ありとあらゆるフィードバックをいただければ幸いです。これが可能かどうかを知る必要があります。前もって感謝します。
コード:
import collection.mutable.Stack
import org.junit.Test
import org.scalatest.junit.JUnitSuite
import org.scalatest.matchers.MustMatchers
import org.scalatest.{GivenWhenThen, FeatureSpec}
class ExampleSpecTest extends FeatureSpec with JUnitSuite with GivenWhenThen with MustMatchers
{
@Test
def featureSpecExample() {
feature("The user can pop an element off the top of the stack") {
info("As a programmer")
info("I want to be able to pop items off the stack")
info("So that I can get them in last-in-first-out order")
scenario("pop is invoked on a non-empty stack") {
given("a non-empty stack")
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
val oldSize = stack.size
when("when pop is invoked on the stack")
val result = stack.pop()
then("the most recently pushed element should be returned")
result must be === 2
and("the stack should have one less item than before")
stack.size must be === oldSize - 1
}
scenario("pop is invoked on an empty stack") {
given("an empty stack")
val emptyStack = new Stack[String]
when("when pop is invoked on the stack")
then("NoSuchElementException should be thrown")
evaluating { emptyStack.pop() } must produce [NoSuchElementException]
and("the stack should still be empty")
emptyStack must be ('empty)
}
}
}
}
このバージョンの ExampleSpecTest を実行すると、次の出力が得られます。
Run starting. Expected test count is: 1
ExampleSpecTest:
Test Starting - ExampleSpecTest: featureSpecExample
Test Succeeded - ExampleSpecTest: featureSpecExample
Run completed in 255 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, ignored 0, pending 0
All tests passed.
期待される所定の時間/時間/時間の出力がレポートに表示されません
期待される:
Run starting. Expected test count is: 1
ExampleSpecTest:
Test Starting - ExampleSpecTest: featureSpecExample
Feature: The user can pop an element off the top of the stack
As a programmer
I want to be able to pop items off the stack
So that I can get them in last-in-first-out order
Scenario: pop is invoked on a non-empty stack
Given a non-empty stack
When when pop is invoked on the stack
Then the most recently pushed element should be returned
And the stack should have one less item than before
Scenario: pop is invoked on an empty stack
Given an empty stack
When when pop is invoked on the stack
Then NoSuchElementException should be thrown
And the stack should still be empty
Test Succeeded - ExampleSpecTest: featureSpecExample Run completed in 96 milliseconds.
Total number of tests run: 2
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, ignored 0, pending 0
All tests passed.