Quinn
12/11/2019, 5:02 PMMatteo Mirk
12/11/2019, 5:04 PMLeoColman
12/11/2019, 5:05 PMclass MyTest : StringSpec() {
override fun listeners() = listOf(myListener)
init {
"My First Test" {
}
"My Second Test" {
}
}
}
Quinn
12/11/2019, 5:07 PMabstract class BaseCacheTest {
protected lateinit var cache: Cache
@Before
fun setup() {
for (i in 0..99) {
cache[i] = i
}
}
@After
fun tearDown() = cache.clear()
@Test
fun shouldClearAllEntries() {
Assert.assertTrue(cache.size > 0)
cache.clear()
Assert.assertTrue(cache.size == 0)
}
@Test
open fun shouldRemoveEntry() {
Assert.assertNotNull(cache[1])
cache.remove(1)
Assert.assertNull(cache[1])
}
LeoColman
12/11/2019, 5:35 PMQuinn
12/11/2019, 6:02 PMLeoColman
12/11/2019, 6:08 PMLeoColman
12/11/2019, 6:08 PMLeoColman
12/11/2019, 6:08 PMQuinn
12/11/2019, 6:17 PMLeoColman
12/11/2019, 6:22 PMclass CacheTest : StringSpec() {
private lateinit var cache: Cache
override fun beforeTest(testCase: TestCase) {
for(i in 0..99)
cache[i] = i
}
override fun afterTest(testCase: TestCase, result: TestResult) {
cache.clear()
}
init {
"Should clear all entries" {
cache.size shouldBeGreaterThan 0
cache.clear()
cache.size shouldBe 0
}
"Should remove entry" {
cache[1] shouldNotBe null
cache.remove(1)
cache[1] shouldBe null
}
}
}
LeoColman
12/11/2019, 6:22 PMQuinn
12/11/2019, 6:24 PMLeoColman
12/11/2019, 6:24 PMQuinn
12/11/2019, 6:25 PMLeoColman
12/11/2019, 6:25 PMLeoColman
12/11/2019, 6:25 PMQuinn
12/11/2019, 6:26 PMQuinn
12/11/2019, 6:27 PMQuinn
12/11/2019, 6:27 PMIt's also important to notice that every Spec is also a TestListener, therefore you may override these functions directly in Spec.
LeoColman
12/11/2019, 6:28 PMLeoColman
12/11/2019, 6:30 PMLeoColman
12/11/2019, 6:30 PMQuinn
12/11/2019, 6:31 PM