Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 在测试期间抑制标准错误_Scala_Specs2 - Fatal编程技术网

Scala 在测试期间抑制标准错误

Scala 在测试期间抑制标准错误,scala,specs2,Scala,Specs2,我正在运行使用第三方库的scalacheck测试。库为我正在检查的属性向std.err打印了很多内容。如何仅在测试执行期间抑制此噪声 我尝试在规范中重定向std.err,但没有效果 def aFailureScenario = prop { input: Input => System.setErr(new PrintStream(new ByteArrayOutputStream())) subject.method(input) must beNone } 不

我正在运行使用第三方库的scalacheck测试。库为我正在检查的属性向std.err打印了很多内容。如何仅在测试执行期间抑制此噪声

我尝试在规范中重定向std.err,但没有效果

  def aFailureScenario = prop { input: Input =>
    System.setErr(new PrintStream(new ByteArrayOutputStream()))
    subject.method(input) must beNone
  }

不确定为什么道具块内的错误设置不起作用,但这是:

class FooSpec extends Specification with BeforeAll {
  ...
  override def beforeAll(): Unit = 
    System.setErr(new PrintStream(new ByteArrayOutputStream()))
}

您的库是否是一个Scala库,它可能正在使用
控制台.err
,而不仅仅是
系统.err
?我也不能复制你看到的东西。在一个简单的规范上它对我很有效。也许你可以试试
Console.setErr
或者
Console.wither