本文整理汇总了Scala中org.scalatest.exceptions.TestFailedException类的典型用法代码示例。如果您正苦于以下问题:Scala TestFailedException类的具体用法?Scala TestFailedException怎么用?Scala TestFailedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestFailedException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TestTimeSpec
//设置package包名称以及导入依赖的类
package akka.testkit
import scala.concurrent.duration._
import org.scalatest.exceptions.TestFailedException
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class TestTimeSpec extends AkkaSpec(Map("akka.test.timefactor" -> 2.0)) {
"A TestKit" must {
"correctly dilate times" taggedAs TimingTest in {
1.second.dilated.toNanos should be(1000000000L * testKitSettings.TestTimeFactor)
val probe = TestProbe()
val now = System.nanoTime
intercept[AssertionError] { probe.awaitCond(false, Duration("1 second")) }
val diff = System.nanoTime - now
val target = (1000000000l * testKitSettings.TestTimeFactor).toLong
diff should be > (target - 500000000l)
diff should be < (target + 500000000l)
}
"awaitAssert must throw correctly" in {
awaitAssert("foo" should be("foo"))
within(300.millis, 2.seconds) {
intercept[TestFailedException] {
awaitAssert("foo" should be("bar"), 500.millis, 300.millis)
}
}
}
}
}
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:35,代码来源:TestTimeSpec.scala
示例2: QuickCheckBinomialHeap
//设置package包名称以及导入依赖的类
package quickcheck
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop
import org.scalacheck.Prop._
import org.scalatest.exceptions.TestFailedException
object QuickCheckBinomialHeap extends QuickCheckHeap with BinomialHeap
@RunWith(classOf[JUnitRunner])
class QuickCheckSuite extends FunSuite with Checkers {
def checkBogus(p: Prop) {
var ok = false
try {
check(p)
} catch {
case e: TestFailedException =>
ok = true
}
assert(ok, "A bogus heap should NOT satisfy all properties. Try to find the bug!")
}
test("Binomial heap satisfies properties.") {
check(new QuickCheckHeap with quickcheck.test.BinomialHeap)
}
test("Bogus (1) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with quickcheck.test.Bogus1BinomialHeap)
}
test("Bogus (2) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with quickcheck.test.Bogus2BinomialHeap)
}
test("Bogus (3) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with quickcheck.test.Bogus3BinomialHeap)
}
test("Bogus (4) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with quickcheck.test.Bogus4BinomialHeap)
}
test("Bogus (5) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with quickcheck.test.Bogus5BinomialHeap)
}
}
开发者ID:vincenzobaz,项目名称:Functional-Programming-in-Scala,代码行数:53,代码来源:QuickCheckSuite.scala
示例3: QuickCheckBinomialHeap
//设置package包名称以及导入依赖的类
package quickcheck
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop
import org.scalacheck.Prop._
import org.scalatest.exceptions.TestFailedException
object QuickCheckBinomialHeap extends QuickCheckHeap with BinomialHeap
@RunWith(classOf[JUnitRunner])
class QuickCheckSuite extends FunSuite with Checkers {
def checkBogus(p: Prop) {
var ok = false
try {
check(p)
} catch {
case e: TestFailedException =>
ok = true
}
assert(ok, "A bogus heap should NOT satisfy all properties. Try to find the bug!")
}
test("Binomial heap satisfies properties.") {
check(new QuickCheckHeap with BinomialHeap)
}
test("Bogus (1) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus1BinomialHeap)
}
test("Bogus (2) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus2BinomialHeap)
}
test("Bogus (3) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus3BinomialHeap)
}
test("Bogus (4) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus4BinomialHeap)
}
test("Bogus (5) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus5BinomialHeap)
}
}
开发者ID:zearom32,项目名称:Courses,代码行数:54,代码来源:QuickCheckSuite.scala
示例4: MisfitRelevanceSpec
//设置package包名称以及导入依赖的类
package org.scalawebtest.integration.gauge
import org.scalatest.exceptions.TestFailedException
import org.scalawebtest.integration.{AdditionalAssertions, ScalaWebTestBaseSpec}
class MisfitRelevanceSpec extends ScalaWebTestBaseSpec with AdditionalAssertions{
path = "/nested.jsp"
"Misfit relevance" should "afa" in {
assertThrowsAndTestMessage[TestFailedException](
fits(<div>
<select title="friendship book questions">
<optgroup label="favorite color">
<option value="green">green</option>
<option value="red">red</option>
<option value="blue">blue</option>
<option value="yellow">yellow</option>
</optgroup>
</select>
<textarea title="hobby"></textarea>
</div>)
)(message => message should startWith("Misfitting Attribute: [title] in [HtmlTextArea[<textarea title=\"hobbies\">]] with value[hobbies] didn't equal [hobby]"))
}
}
开发者ID:unic,项目名称:ScalaWebTest,代码行数:25,代码来源:MisfitRelevanceSpec.scala
示例5: jsonGaugeFitting
//设置package包名称以及导入依赖的类
package org.scalawebtest.integration.json
import org.scalatest.exceptions.TestFailedException
import play.api.libs.json.Json
//Can only be used in specs which request /jsonResponse.json.jsp
trait FitsTypeMismatchBehavior {
self: ScalaWebTestJsonBaseSpec =>
def jsonGaugeFitting(gaugeType: GaugeType): Unit = {
def dijkstra = Json.parse(webDriver.getPageSource)
"When verifying JSON using fitsTypes or fitsTypesAndArraySizes" should
"fail when a String is expected, but an Int provided" in {
assertThrows[TestFailedException] {
dijkstra fits gaugeType of """{"yearOfBirth": ""}"""
}
}
it should "fail when an Int is expected, but a String provided" in {
assertThrows[TestFailedException] {
dijkstra fits gaugeType of """{"name": 0}"""
}
}
it should "fail when a Boolean is expected, but a String provided" in {
assertThrows[TestFailedException] {
dijkstra fits gaugeType of """{"name": true}"""
}
}
it should "fail when an Object is expected, but a String provided" in {
assertThrows[TestFailedException] {
dijkstra fits gaugeType of """{"name": {}}"""
}
}
it should "fail when an Array is expected, but a String provided" in {
assertThrows[TestFailedException] {
dijkstra fits gaugeType of """{"name": []}"""
}
}
it should "fail when a property is missing" in {
assertThrows[TestFailedException] {
dijkstra fits gaugeType of """{"thesis": "Communication with an Automatic Computer"}"""
}
}
}
}
开发者ID:unic,项目名称:ScalaWebTest,代码行数:46,代码来源:FitsTypeMismatchBehavior.scala
示例6: FitsTypesAndArraySizesSpec
//设置package包名称以及导入依赖的类
package org.scalawebtest.integration.json
import org.scalatest.exceptions.TestFailedException
import play.api.libs.json.{JsValue, Json}
class FitsTypesAndArraySizesSpec extends ScalaWebTestJsonBaseSpec with FitsTypeMismatchBehavior {
path = "/jsonResponse.json.jsp"
def dijkstra: JsValue = Json.parse(webDriver.getPageSource)
"The json response representing Edsger Dijkstra" should "use the correct types" in {
dijkstra fits typesAndArraySizes of
"""{
| "name": "",
| "firstName": "",
| "isTuringAwardWinner": true,
| "theories": ["", ""],
| "universities": [{"name": "", "begin": 0, "end": 0}, {}, {}, {}]
|}
""".stripMargin
}
it should "not have only a single entry in universities" in {
assertThrows[TestFailedException] {
dijkstra fits typesAndArraySizes of
"""{
| "universities": [{}]
|}
""".stripMargin
}
}
it should behave like jsonGaugeFitting(typesAndArraySizes)
}
开发者ID:unic,项目名称:ScalaWebTest,代码行数:33,代码来源:FitsTypesAndArraySizesSpec.scala
示例7: StdInParserSpec
//设置package包名称以及导入依赖的类
package nl.soqua.lcpi.repl.parser
import nl.soqua.lcpi.ast.lambda.{LambdaAbstraction, Variable}
import nl.soqua.lcpi.repl.monad.ReplMonad
import org.scalatest.exceptions.TestFailedException
import org.scalatest.{Matchers, WordSpecLike}
class StdInParserSpec extends StdInParserTester with WordSpecLike with Matchers {
"A std in parser" should {
"parse the standard commands" in {
List(
"help" -> ReplMonad.help(),
"quit" -> ReplMonad.quit(),
"show" -> ReplMonad.showContext(),
"reset" -> ReplMonad.reset(),
"trace" -> ReplMonad.trace(),
"ascii" -> ReplMonad.ascii(),
"load appel.csv" -> ReplMonad.load("appel.csv"),
"reload" -> ReplMonad.reload()
) foreach {
case (input, output) => input >> output
}
}
"parse an expression" in {
"?x.x" >> ReplMonad.evalExpression(LambdaAbstraction(Variable("x"), Variable("x")))
}
"don't parse anything that is not a valid ? expression" in {
assertThrows[TestFailedException] {
"# foo" >> ReplMonad.help()
}
}
"parse a De Bruijn Index command" in {
"dbi ?x.x" >> ReplMonad.deBruijnIndex(LambdaAbstraction(Variable("x"), Variable("x")))
}
"don't parse an invalid De Bruijn Index command" in {
assertThrows[TestFailedException] {
"dbi # foo" >> ReplMonad.help()
}
}
}
}
开发者ID:kevinvandervlist,项目名称:lcpi,代码行数:42,代码来源:StdInParserSpec.scala
示例8: ReplParserSpec
//设置package包名称以及导入依赖的类
package nl.soqua.lcpi.parser.repl
import nl.soqua.lcpi.ast.interpreter.Assignment
import nl.soqua.lcpi.ast.lambda.Expression
import org.scalatest.exceptions.TestFailedException
import org.scalatest.{Matchers, WordSpecLike}
class ReplParserSpec extends ReplParserTester with WordSpecLike with Matchers {
import Expression._
val I = V("I")
val x = V("x")
"A REPL parser" should {
"parse an identity function" in {
"?x.x" >> ?(x, x)
}
"parse an identity function assignment" in {
"I := ?x.x" >> Assignment(I, ?(x, x))
}
"throw an error if the LHS is not completely uppercase" in {
assertThrows[TestFailedException] {
"MYVar := x" >> x
}
}
}
}
开发者ID:kevinvandervlist,项目名称:lcpi,代码行数:29,代码来源:ReplParserSpec.scala
示例9: defaultWait
//设置package包名称以及导入依赖的类
package io.buoyant.test
import com.twitter.conversions.time._
import com.twitter.util.{Await, Duration, Future, TimeoutException}
import org.scalatest.concurrent.Eventually
import org.scalatest.exceptions.TestFailedException
import org.scalatest.time.{Millis, Span}
trait Awaits extends Eventually {
def defaultWait: Duration =
sys.env.get("CI_TERRIBLENESS").map(Duration.parse(_)).getOrElse(2.seconds)
implicit override val patienceConfig =
PatienceConfig(timeout = scaled(Span(defaultWait.inMillis, Millis)))
def awaitStackDepth: Int = 5
def await[T](t: Duration)(f: => Future[T]): T =
try Await.result(f, t) catch {
case cause: TimeoutException =>
throw new TestFailedException(s"operation timed out after $t", cause, awaitStackDepth)
}
def await[T](ev: Events[T]): (T, Events[T]) = ev match {
case Events.None() =>
throw new TestFailedException(s"events underflow", awaitStackDepth)
case ev =>
await(ev.next())
}
def await[T](f: => Future[T]): T =
await(defaultWait)(f)
}
开发者ID:linkerd,项目名称:linkerd,代码行数:36,代码来源:Awaits.scala
注:本文中的org.scalatest.exceptions.TestFailedException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论