dave08
08/20/2024, 2:06 PMvar
to modify during the testdave08
08/20/2024, 2:56 PMCLOVIS
08/20/2024, 4:08 PMinterface Dep
class Impl1 : Dep
class Impl2 : Dep
class SystemYouWantToTest(val dep: Dep)
val impl1 by prepared { Impl1() }
val impl2 by prepared { Impl2() }
fun systemTests(system: Prepared<SystemYouWantToTest>) = suite("Test the system you want to test") {
โฆ
}
suite("All your tests") {
val deps: List<Prepared<Dep>> = listOf(impl1, impl2)
for (dep in deps) {
val system by prepared { SystemYouWanToTest(dep()) }
systemTests(system)
}
}
This can be simplified further if you use the paramaterize
extension module (thanks to #C06083PAKEK!)CLOVIS
08/20/2024, 4:08 PMdatetime
compat modules have test clocks ready to useCLOVIS
08/20/2024, 4:09 PMPrepared<WhatYouWantToTest>
is really helpfuldave08
08/20/2024, 4:15 PMtheAll I see iscompat modules have test clocks ready to usedatetime
time
in the reference section... I guess I'd do prepared { Foo(time.clock) }
?CLOVIS
08/20/2024, 4:17 PMCLOVIS
08/20/2024, 4:17 PMtime.clock
CLOVIS
08/20/2024, 4:18 PMdave08
08/20/2024, 4:20 PMCLOVIS
08/20/2024, 4:23 PMdave08
08/21/2024, 6:12 AMUsing the virtual time
Often,Maybe could clarify that it's not just oriented on time but also dates, and that there's ais insufficient: we want to trigger algorithms at specific dates in time, for example to check that an algorithm behaves correctly even at midnight on New Year's. Prepared offers compatibility modules to generate datetime objects from popular libraries.time.nowMillis
Clock
instance that's instantiated and can be manipulated in the test... maybe have the first example use a val foo by prepared { Foo(time.clock) }
, that'll bring out the feature.
Maybe this could be renamed as Manipulating date and time
, to show the difference with the first section that really only has millis to work with, whereas in with the module, one can work on date and time in a consistent way.
I think the problem is that nowadays we're overloaded with information on the Internet, and people (including me) tend to skim through information and only really read what's relevant -- so in my case, I quickly went through the code examples missing the implecation that time.set(...)
must somehow be usable when instatiating our test subject.CLOVIS
08/21/2024, 7:21 AMdave08
08/21/2024, 7:22 AMdave08
08/21/2024, 7:23 AMCLOVIS
08/21/2024, 7:23 AMdave08
08/21/2024, 7:23 AMCLOVIS
08/21/2024, 7:23 AMdave08
08/21/2024, 7:24 AMCLOVIS
08/21/2024, 7:25 AMCLOVIS
08/21/2024, 7:25 AMtime.set("2024-01-01TOO:OOZ")
at the start of each test if you want, that's fine IMOdave08
08/21/2024, 7:28 AMCLOVIS
08/21/2024, 7:29 AM