All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.iterators.stir.testkit.TestFrameworkInterface.scala Maven / Gradle / Ivy

The newest version!
package pl.iterators.stir.testkit

import org.scalatest.exceptions.TestFailedException
import org.scalatest.{ BeforeAndAfterAll, Suite }
import pl.iterators.stir.server.ExceptionHandler

trait TestFrameworkInterface {

  def cleanUp(): Unit

  def failTest(msg: String): Nothing

  def testExceptionHandler: ExceptionHandler
}
//#source-quote

object TestFrameworkInterface {

  trait Scalatest extends TestFrameworkInterface with BeforeAndAfterAll {
    this: Suite =>

    def failTest(msg: String) = throw new TestFailedException(msg, 11)

    abstract override protected def afterAll(): Unit = {
      cleanUp()
      super.afterAll()
    }

    override val testExceptionHandler = ExceptionHandler {
      case e: org.scalatest.exceptions.TestFailedException => throw e
      case e: java.lang.AssertionError                     => throw e
    }
  }
}

object Specs2FrameworkInterface {
  import org.specs2.execute.{ Failure, FailureException }
  import org.specs2.specification.AfterAll

  trait Specs2 extends TestFrameworkInterface with AfterAll {
    def failTest(msg: String): Nothing = throw new FailureException(Failure(msg))

    override def afterAll(): Unit = cleanUp()

    override val testExceptionHandler = ExceptionHandler {
      case e: org.specs2.execute.FailureException => throw e
      case e: java.lang.AssertionError            => throw e
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy