Scala中的MUnit具有丰富的过滤功能

Scala中的MUnit具有丰富的过滤功能,scala,munit,Scala,Munit,MUnit是一个新的Scala测试库,具有 以下是我无法工作的网站示例: import scala.util.Properties import munit._ object Windows213 extends Tag("Windows213") class MySuite extends FunSuite { // reminder: type Test = GenericTest[Any] override def munitNewTest(test: Test

MUnit是一个新的Scala测试库,具有

以下是我无法工作的网站示例:

import scala.util.Properties
import munit._
object Windows213 extends Tag("Windows213")
class MySuite extends FunSuite {
  // reminder: type Test = GenericTest[Any]
  override def munitNewTest(test: Test): Test = {
    val isIgnored =
      options.tags(Windows213) && !(
        Properties.isWin &&
        Properties.versionNumberString.startsWith("2.13")
      )
    if (isIgnored) test.withBody(() => Ignore)
    else test
  }

  test("windows-213".tag(Windows213)) {
    // Only runs when operating system is Windows and Scala version is 2.13
  }
  test("normal test") {
    // Always runs like a normal test.
  }
}
options.tags
更改为
test.tags
可解决其中一个错误

if(isIgnored)test.withBody(()=>Ignore)
行仍然出错,并显示以下消息:

[error] /Users/powers/Documents/code/my_apps/munit-example/src/test/scala/com/github/mrpowers/munit/example/RichFiltersSpec.scala:16:40: type mismatch;
[error]  found   : munit.Tag
[error]  required: MySuite.this.TestValue
[error]     (which expands to)  scala.concurrent.Future[Any]
[error]     if (isIgnored) test.withBody(() => Ignore)
[error]                                        ^
[error] one error found
[error] (Test / compileIncremental) Compilation failed
更新

这项功能,但


将在示例修复后报告更新。

自版本0.6.0-M1起已修复

此代码按预期工作:

package com.github.mrpowers.munit.example

import scala.util.Properties
import munit._

object Windows213 extends Tag("Windows213")

class MySuite extends FunSuite {

  override def munitTestTransforms = super.munitTestTransforms ++ List(
    new TestTransform("Windows213", { test =>
      val isIgnored =
        test.tags(Windows213) && !(
          Properties.isWin &&
            Properties.versionNumberString.startsWith("2.13")
          )
      if (isIgnored) test.tag(Ignore)
      else test
    })
  )

  test("windows-213".tag(Windows213)) {
    assertEquals(2, 3)
  }

  test("normal test") {
    assertEquals(2, 2)
  }

}

从github上的源代码来看,这看起来像是
if(isIgnored)test.withTags(Set(Ignore))