From 2e599e4f1d1e1166a2cdfe4b863e8377ae96ea11 Mon Sep 17 00:00:00 2001 From: Emily Bache Date: Tue, 10 Sep 2019 10:40:56 +0200 Subject: [PATCH] Use approval testing framework for statement printer test It's better to store the expected text in a separate file instead of mixed in together with the kotlin test code. This is for several reasons - it is easier to read when the expected value is on several lines - it is easier to update using a diff merge tool - it is easier to read the VCS history since it will probably change more frequently than the rest of the test code --- kotlin/build.gradle | 1 + kotlin/gradle/wrapper/gradle-wrapper.properties | 5 +++-- ...tPrinterTests.exampleStatement$kotlin.approved.txt | 6 ++++++ kotlin/src/test/kotlin/StatementPrinterTests.kt | 11 +++-------- 4 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 kotlin/src/test/kotlin/StatementPrinterTests.exampleStatement$kotlin.approved.txt diff --git a/kotlin/build.gradle b/kotlin/build.gradle index eb9cb70..57e2ec7 100644 --- a/kotlin/build.gradle +++ b/kotlin/build.gradle @@ -17,6 +17,7 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' testCompile("org.junit.jupiter:junit-jupiter-params:5.4.2") + testCompile 'com.approvaltests:approvaltests:3.2.0' } test { diff --git a/kotlin/gradle/wrapper/gradle-wrapper.properties b/kotlin/gradle/wrapper/gradle-wrapper.properties index 290541c..35ddd86 100644 --- a/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Tue Sep 10 10:36:28 CEST 2019 +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/kotlin/src/test/kotlin/StatementPrinterTests.exampleStatement$kotlin.approved.txt b/kotlin/src/test/kotlin/StatementPrinterTests.exampleStatement$kotlin.approved.txt new file mode 100644 index 0000000..fa59f94 --- /dev/null +++ b/kotlin/src/test/kotlin/StatementPrinterTests.exampleStatement$kotlin.approved.txt @@ -0,0 +1,6 @@ +Statement for BigCo + Hamlet: $650.00 (55 seats) + As You Like It: $580.00 (35 seats) + Othello: $500.00 (40 seats) +Amount owed is $1,730.00 +You earned 47 credits diff --git a/kotlin/src/test/kotlin/StatementPrinterTests.kt b/kotlin/src/test/kotlin/StatementPrinterTests.kt index d54adab..cba9aa4 100644 --- a/kotlin/src/test/kotlin/StatementPrinterTests.kt +++ b/kotlin/src/test/kotlin/StatementPrinterTests.kt @@ -1,17 +1,12 @@ -import org.junit.jupiter.api.Assertions.assertEquals + import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Test +import org.approvaltests.Approvals.verify class StatementPrinterTests { @Test internal fun exampleStatement() { - val expected = "Statement for BigCo\n" + - " Hamlet: \$650.00 (55 seats)\n" + - " As You Like It: \$580.00 (35 seats)\n" + - " Othello: \$500.00 (40 seats)\n" + - "Amount owed is \$1,730.00\n" + - "You earned 47 credits\n" val plays = mapOf( "hamlet" to Play("Hamlet", "tragedy"), @@ -30,7 +25,7 @@ class StatementPrinterTests { val statementPrinter = StatementPrinter() val result = statementPrinter.print(invoice, plays) - assertEquals(expected, result) + verify(result) } @Test