Quick testing tips #7


Plant Timber tree to have timber logs in tests




import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import timber.log.Timber

class StdoutTree : Timber.Tree() {
  override fun log(p: Int, tag: String?, m: String, t: Throwable?) {
    println("$p: [$tag], $m")
  }
}

class Test {
  @BeforeAll
  fun setup() {
    Timber.plant(StdoutTree())
  }

  @Test
  fun `it should pass`() {

  }
}



Need see Timber logs in unit tests? Plant custom StdoutTree to delegate all logging to standard output.



Read next:


Loading ...
Failed to load data.