As I have a collection of scala tests that connect with remote services (some of which may not be available at the time of test execution), I would like to have a way of indicating Scala tests that should be ignored, if the time-out exceeds a desired threshold.

Indeed, I could enclose the body of a test in a future and have it auto-pass, if the time-out is exceeded but having slow tests silently pass strikes me as risky. It would be better if it were explicitly skipped during the test run. So, what I would really like is something like the following:

 ignorePast(10 seconds) should "execute a service that is sometimes unavailable" in {
      invokeServiceThatIsSometimesUnavailable()
      ....
 }

Looking at the ScalaTest documentation, I don't see this feature supported directly but suspect that there might be away to add this capability? Indeed, I could just add a "tag" to "slow" tests and tell the runner not to execute them, but I would rather the tests be automatically skipped when the timeout is exceeded.

有帮助吗?

解决方案

I believe that's not something you're test framework should be responsible for. Wrap your invokeServiceThatIsSometimesUnavailable() in an exception handling block and you'll be fine.

try {
  invokeServiceThatIsSometimesUnavailable()
} catch {
  case e : YourServiceTimeoutException => reportTheIgnoredTest()
}

其他提示

I agree with Maciej that exceptions are probably the best way to go, since the timeout happens within your test itself.

There's also assume (see here), which allows to cancel a test if some pre-requisite fails. You could use it also within a single test, I think.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top