【问题标题】:Executing a task dependency for test failure in SBT在 SBT 中执行测试失败的任务依赖项
【发布时间】:2013-04-10 01:23:56
【问题描述】:

如果我的测试成功完成,下面的代码将在我的 build.sbt 中执行。它播放了一首美妙的小曲子,告诉我我的测试已成功完成,让我不必像肮脏的哈利那样盯着终端机。

test <<= (test in Test) map { result =>
  import java.io.File
  import javax.sound.sampled._
  val clip = AudioSystem.getClip();
  val soundfile = new File("success.wav")
  val inputStream = AudioSystem.getAudioInputStream(soundfile);
  clip.open(inputStream);
  clip.start();
  result
}

所以我用 ~test 开始我的测试,然后就结束了。每次我在编辑器中点击保存时,测试会自动神奇地重新运行,如果它们通过了,你就会听到叮当声。

问题是:如果测试失败,我该如何播放声音?目前它只是对失败保持沉默。

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    Handling Failure。例如,

    ... test in Test mapR {
      case Inc(inc: Incomplete) =>
         ... play failure sound ...
         throw inc
      case Value(v) =>
         ... play success sound ...
         v
    }
    

    【讨论】:

      猜你喜欢
      • 2016-04-22
      • 1970-01-01
      • 2013-12-29
      • 2012-08-15
      • 2022-01-12
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多