Skip to content

Instantly share code, notes, and snippets.

@logi
Created September 14, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logi/0fa187df39f449c666ab79c330b2fb79 to your computer and use it in GitHub Desktop.
Save logi/0fa187df39f449c666ab79c330b2fb79 to your computer and use it in GitHub Desktop.
Why does the second test faile?
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
/** Test that tests run and that particular testing techniques work. */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class KtTestTest {
var state = "initial"
@Test
fun `first test sees original state`() {
println("this: ${this}")
println("state: ${state}")
assertEquals("initial", state)
state = "modified"
}
@Test
fun `state changed by first test`() {
println("this: ${this}")
println("state: ${state}")
assertEquals("modified", state)
state = "modified again"
}
}
"""
Output:
this: KtTestTest@7113b13f
state: initial
org.opentest4j.AssertionFailedError:
Expected :modified
Actual :initial
this: KtTestTest@7113b13f
state: initial
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment