开发者

Cannot get FeatureSpec structure to show up in the output when combined with JUnitSuite

I am trying to use Scala's capabilty of running a cl开发者_Python百科ass with either JUnit or ScalaTest. I took the example given for FeatureSpec and combined it with the example using JUnitSuite. I am having a problem generating the given/when/then output of Scalatest.FeatureSpec structure in the output (console) when combined with JUnitSuite. Any and all feedback would be greatly appreciated. Need to know if this is even possible. Thanks in advance.

code:

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)
     }
   }
 }
}

when I run this version of ExampleSpecTest, I am getting the following output:

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.

I am not getting any of the expected given/when/then output in the report

Expected:

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜