throwA[ExceptionType](message = "boom")另外检查异常消息是否符合预期
但是当我使用它时,消息显然在整个堆栈跟踪上匹配,而不仅仅是异常消息.
测试
"cont'd what if -- running test again shows that the app has already died" in {
running(new FakeApplication(additionalConfiguration = inLocalPostgresDatabase())) {
db2 withSession {
val comboboxOpsClass = new ComboboxOps(database)
}
} must throwA[SQLException](message = "Attempting to obtain a connection from a pool that has already been shutdown")
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
[error] 'Attempting to obtain a connection from a pool that has already been shutdown.
[error] Stack trace of location where pool was shutdown follows:
[error] java.lang.Thread.getStackTrace(Thread.java:1568)
[error] com.jolbox.bonecp.BoneCP.captureStackTrace(BoneCP.java:572)
[error] com.jolbox.bonecp.BoneCP.shutdown(BoneCP.java:161)
Run Code Online (Sandbox Code Playgroud)
还有很多行
[error] org.specs2.execute.ResultExecution$class.execute(ResultExecution.scala:22)
[error] org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:116)
[error] org.specs2.specification.FragmentExecution$class.executeBody(FragmentExecution.scala:28)
[error]
[error] sbt.ForkMain$Run.runTestSafe(ForkMain.java:211)
[error] sbt.ForkMain$Run.runTests(ForkMain.java:187)
[error] sbt.ForkMain$Run.run(ForkMain.java:251)
[error] sbt.ForkMain.main(ForkMain.java:97)
[error] ' doesn't match '.*Attempting to obtain a connection from a pool that has already been shutdown.*' (FakeApplicationSpec.scala:138)
Run Code Online (Sandbox Code Playgroud)
有人能指出我对specs2的这种用法的一个有效例子吗?
我讨厌说它,但我从来没有找到一种通用的方法来发现文本是什么,而不是让它发生并在事后添加...或者转到异常的来源并从那里复制它.这是我在Novus-JDBC第91行所做的:
"handle when take more than it can give" in{
val iter0 = nonCounter()
val iter = iter0 slice (0,10)
(iter next () must be greaterThan 0) and
(iter next () must be greaterThan 0) and
(iter next () must be equalTo -1) and
(iter next () must be equalTo 3) and
(iter.hasNext must beFalse) and
(iter next() must throwA(new NoSuchElementException("next on empty iterator")))
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3782 次 |
| 最近记录: |