title: Kotlin - Don't run unit test until lateinit property is initialized
body: <p>I have a case where the unit of code I'm testing is running on a different thread and so the test executes and fails before the unit has finished executing:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class Tests {
      private lateinit var result: String
  
      @BeforeAll
      fun setup() {
          DataService().subscribe {
              result = it
          }
      }
  
      @Test
      fun `get result from data service`() {
          assert(result.contains(&quot;Hello&quot;))
      }
  }
  </code></pre>
  <p>When the test runs, I get the following exception:</p>
  <blockquote>
  <p>kotlin.UninitializedPropertyAccessException: lateinit property result has not been initialized</p>
  </blockquote>
  <p>How can I ensure that the tests don't run before <code>result</code> has been initialized?</p>