Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 607 Bytes

File metadata and controls

26 lines (18 loc) · 607 Bytes
id title slug
autoclose
Closing resources automatically
autoclose.html

You can let Kotest close resources automatically after all tests have been run:

class StringSpecExample : StringSpec() {

  val reader = autoClose(StringReader("xyz"))

  init {
    "your test case" {
      // use resource reader here
    }
  }
}

Resources that should be closed this way must implement java.lang.AutoCloseable. Closing is performed in reversed order of declaration after the return of the last spec interceptor.