Hello has anyone had this with kotest where if you...
# kotest
m
Hello has anyone had this with kotest where if you need to declare private functions in a test you must do so before your tests? Seems a bit odd. Is it just the case of wacking that functionality in an 
init {}
 block?
c
you can also declare them at the bottom outside the init block.
t
what do you mean?
Copy code
class Test : StringSpec() {
  init {
      "t" {
        test()
      }
  }

  private fun test() = ""
}
there is also this version
Copy code
class Test : StringSpec({
  fun test() = ""
  
  "t" {
    test()
  }
})
but this one is a local function, https://kotlinlang.org/docs/functions.html#local-functions, as in the second example code is inside the constructor
🙏 1
c
if you just want to put some tests into a function for reuse you can just use the extract function refactoring and IDEA will do the right thing
🙏 1
c
@Matt Watson was asking this on my behalf. I was originally using the contructor syntax which meant as local functions they had to be defined first which isn’t desirable. (Public first, private second - in this case tests first, helpers second). I’ve gone with the
init
approach. I was originally avoiding this syntax as it seemed less clean than the constructor approach and has the effect of indenting everything. But it’s preferable to having to define functions upfront.