Add jacoco dependency, convert TexttestFixtures to tests. Update README with results and next steps.

This commit is contained in:
Jacek Weremko 2024-06-15 13:55:33 +02:00
parent 77b6522361
commit cf6f9f54fe
4 changed files with 58 additions and 1 deletions

View File

@ -32,3 +32,14 @@ There are instructions in the [TextTest Readme](../texttests/README.md) for sett
2. Break complex statements, make code longer and simpler
3. understand algorithm and propose better solution
### Execution
TexttestFixtures indeed do not cover all paths, based on jacoco coverage:
![img.png](img.png)
There are two ways to advance:
1. manually craft extra test cases
2. auto generate a bunch of test cases
I prefer to go with (2) because it seems to me to be more resilient way. I need to check if execution
time is not bloated. Also minimize number of test cases.

View File

@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.10"
application
jacoco
}
group = "com.gildedrose"
@ -22,6 +23,11 @@ tasks.test {
testLogging {
events("passed", "skipped", "failed")
}
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
}
// config JVM target to 1.8 for kotlin compilation tasks

BIN
Kotlin/img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -2,6 +2,15 @@ package com.gildedrose
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.Arguments.of
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream
internal class GildedRoseTest {
@ -10,10 +19,41 @@ internal class GildedRoseTest {
val items = listOf(Item("foo", 0, 0))
val app = GildedRose(items)
app.updateQuality()
assertEquals("fixme", app.items[0].name)
assertEquals("foo", app.items[0].name)
}
@ParameterizedTest
@ArgumentsSource(GildedRoseArgumentsProvider::class)
fun `should update quality`(item: Item, expectedQuality: Int, expectedSellIn: Int) {
val itemName = item.name
val items = listOf(item)
val app = GildedRose(items)
app.updateQuality()
assertAll(
{ assertEquals(itemName, app.items[0].name) },
{ assertEquals(expectedQuality, app.items[0].quality) },
{ assertEquals(expectedSellIn, app.items[0].sellIn) }
)
}
class GildedRoseArgumentsProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): Stream<out Arguments?> {
return Stream.of(
of(Item("+5 Dexterity Vest", 10, 20), 19, 9),
of(Item("Aged Brie", 2, 0), 1, 1),
of(Item("Elixir of the Mongoose", 5, 7), 6, 4),
of(Item("Sulfuras, Hand of Ragnaros", 0, 80), 80, 0),
of(Item("Sulfuras, Hand of Ragnaros", -1, 80), 80, -1),
of(Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), 21, 14),
of(Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), 50, 9),
of(Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), 50, 4),
// this conjured item does not work properly yet
// of(Item("Conjured Mana Cake", 3, 6), 5, 2), // TODO: enabled and fix after refactor
)
}
}
}