How to fork the jvm for each test in sbt

前端 未结 2 1668
[愿得一人]
[愿得一人] 2021-01-11 13:24

I am working with some classes that (for some reason) can only be used once within a single VM. My test cases work if I run them individually (fork := true) ena

相关标签:
2条回答
  • 2021-01-11 13:44

    Using non-deprecated syntax:

    testGrouping in Test := (definedTests in Test).value map { test =>
      Tests.Group(name = test.name, tests = Seq(test), runPolicy = Tests.SubProcess(
        ForkOptions(
          javaHome.value,
          outputStrategy.value,
          Nil,
          Some(baseDirectory.value),
          javaOptions.value,
          connectInput.value,
          envVars.value
        )))
    }
    
    0 讨论(0)
  • 2021-01-11 14:00

    It turns out this is fairly easy to achieve. The documentation is sufficient and can be found at Testing - Forking tests

    // Define a method to group tests, in my case a single test per group
    def singleTests(tests: Seq[TestDefinition]) =
      tests map { test =>
        new Group(
          name = test.name,
          tests = Seq(test),
          runPolicy = SubProcess(javaOptions = Seq.empty[String]))
      }
    
    // Add the following to the `Project` settings
    testGrouping in Test <<= definedTests in Test map singleTests
    
    0 讨论(0)
提交回复
热议问题