christophsturm
12/01/2023, 6:51 PMval context = describe {
val assertionError: AssertionError = AssertionError("failed")
describe("with a typical valid root context") {
val ctx =
RootContext("root context") {
test("failed test") { throw assertionError }
}
describe("executing all the tests") {
val contextInfo = assertNotNull(execute(ctx) as? ContextInfo)
describe("reports failed tests") {
val failure =
contextInfo.tests.values
.awaitAll()
.map { it.result }
.filterIsInstance<Failure>()
.single()
it("reports exception for failed tests") {
expectThat(failure.failure) {
get { stackTraceToString() }
.isEqualTo(assertionError.stackTraceToString())
}
}
}
so the fixture is basically the rootcontext (ctx), and the assertionError (because in the test I need to have the assertion error to check that exactly that error is reported as failure)
when I try to convert this to a given style (with my own made up test dsl) I have to make the context field nullable and mutable, because I need the given class constructed to reference the exception in my context.
data class Given(
val assertionError: java.lang.AssertionError,
var context: RootContext? = null
)
val test =
context(
"contextExecutorTest port",
given = {
val given = Given(AssertionError("failed"))
given.context =
RootContext("root context") {
test("failed test") {
throw given.assertionError
}
}
given
}
)
is there a better way to do this and avoid making the context nullable?christophsturm
12/02/2023, 2:06 PMclass Given {
val assertionError: java.lang.AssertionError = AssertionError("failed")
val context: RootContext = RootContext("root context") {
test("failed test") {
throw assertionError
}
}
}
and then just given={Given()}