我想做类似的事情:

class MySpec extends Specification with BeforeAfterExample {
  var testName
  var clientDir

  def before {
    testName = fragmentName.replaceAll(" ", "-")
    clientDir = new File(workspaceRoot, testName)
    clientDir.mkdirs()
  }

  def after {
    FileUtils.deleteDirectory(clientDir)
  }
}

最佳答案

这可能会起作用:

class MySpec extends Specification with BeforeAfterExample {
  var currentExample = 0
  var testName = ""
  var clientDir:File = null

  def before {
    testName = is.examples(currentExample).desc.toString.replaceAll(" ", "-")
    clientDir = new File(workspaceRoot, testName)
    clientDir.mkdirs()
  }

  def after {
    FileUtils.deleteDirectory(clientDir)
    currentExample += 1
  }
}

我认为,如果不这样做,就不会在前后方法中获得很多上下文。

10-06 09:15