christophsturm
12/15/2020, 1:41 PMobject MyObj { val blah=getBlah }
, when is getBlah called? when the containing file is imported? or when a method references MyObj.blah
?Marc Knaup
12/15/2020, 1:47 PMMyObj
.
On JS upon script loading.
I don’t know on Native.Rob Elliot
12/15/2020, 1:48 PMMarc Knaup
12/15/2020, 1:49 PMRob Elliot
12/15/2020, 1:54 PMfun getBlah(): String {
println("getBlah called")
return "blah"
}
object MyObj { val blah = getBlah() }
fun main() {
println("start")
val myObj = MyObj
println("MyObj referenced")
val blah = myObj.blah
println("MyObj.blah referenced; was $blah")
}
Rob Elliot
12/15/2020, 1:56 PMstart
getBlah called
MyObj referenced
MyObj.blah referenced; was blah
on the JVM, which shows it isn’t loaded immediately, but is loaded when MyObj
is first referenced rather than when MyObj.blah
is referenced.Marc Knaup
12/15/2020, 1:56 PMchristophsturm
12/15/2020, 1:57 PMMarc Knaup
12/15/2020, 1:58 PMchristophsturm
12/15/2020, 1:58 PMchristophsturm
12/15/2020, 2:01 PMMarc Knaup
12/15/2020, 2:02 PMfun preload() {
Obj1
Obj2
Obj3
// …
}
Rob Elliot
12/15/2020, 2:03 PMchristophsturm
12/15/2020, 2:04 PM```package nanotest
import strikt.api.expectThat
import strikt.api.expectThrows
import strikt.assertions.all
import strikt.assertions.containsExactlyInAnyOrder
import strikt.assertions.hasSize
import strikt.assertions.isA
import strikt.assertions.isEqualTo
import strikt.assertions.isFalse
import strikt.assertions.isLessThan
import strikt.assertions.isTrue
import strikt.assertions.map
import java.lang.management.ManagementFactory
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
fun main() {
val testFinished = CompletableFuture<Unit>()
val failingTestFinished = CompletableFuture<Throwable>()
val results = Suite {
test("firstTest") {
expectThat(true).isTrue()
testFinished.complete(Unit)
}
test("failing test") {
try {
expectThat(true).isFalse()
} catch (e: AssertionError) {
failingTestFinished.complete(e)
throw e
}
}
context("child context") {
context("grandchild context") {
test("failing test") {
expectThat(true).isFalse()
}
}
}
}.run()
expectThat(results) {
get(SuiteResult::allOk).isFalse()
get(SuiteResult::failedTests).hasSize(2).all {
get(TestFailure::name).isEqualTo("failing test")
get(TestFailure::throwable).isA<AssertionError>()
}
get(SuiteResult::contexts).map { it.name }
.containsExactlyInAnyOrder("root", "child context", "grandchild context")
}
expectThrows<RuntimeException> { results.check() }
testFinished.get(1, TimeUnit.SECONDS)
Suite(listOf(TestContextTest.context, SuiteTest.context, ContextTest.context)).run().check()
val uptime = ManagementFactory.getRuntimeMXBean().uptime
println("finished after: ${uptime}ms")
expectThat(uptime).isLessThan(1000) // lets see how far we can get with one second
}
and right now i have a list of test classes in my bootstrap test. (i run the bootstrap test in main and after checking that it runs all the tests and fails on failure i run the rest via the normal test runner)
right now i have a list of all the test objects there and i wonder if i can automate it while staying in my 1000ms budgetMarc Knaup
12/15/2020, 2:42 PMchristophsturm
12/15/2020, 2:47 PMSuite(listOf(TestContextTest.context, SuiteTest.context, ContextTest.context)).run().check()
christophsturm
12/15/2020, 2:48 PMRob Elliot
12/15/2020, 2:51 PMRob Elliot
12/15/2020, 2:52 PMMarc Knaup
12/15/2020, 2:54 PMchristophsturm
12/15/2020, 3:06 PMchristophsturm
12/15/2020, 3:07 PMMarc Knaup
12/15/2020, 3:07 PMchristophsturm
12/15/2020, 3:08 PMRob Elliot
12/15/2020, 3:11 PMchristophsturm
12/15/2020, 3:14 PMAnimesh Sahu
12/16/2020, 11:36 AM