How to use CompareJsonOptions class of io.kotest.assertions.json package

Best Kotest code snippet using io.kotest.assertions.json.CompareJsonOptions

compare.kt

Source:compare.kt Github

copy

Full Screen

1@file:Suppress("unused")2package io.kotest.assertions.json3@Deprecated("Json comparison options is now specified with `CompareJsonOptions`", ReplaceWith("TypeCoercion"))4enum class CompareMode {5 /**6 * Types must be identical and compare by value.7 *8 * For example, `"true"` and `true` will not match because one is a string, and the other is a boolean.9 * But `2.99E9` and `299000000` are considered equal as they are the same number, just in a different format.10 * `"100"` and `100` would not match as they are different types (string vs number).11 */12 @Deprecated(13 "Json comparison options is now specified with `CompareJsonOptions`",14 ReplaceWith("TypeCoercion.Disabled")15 )16 Strict,17 /**18 * Compare by value, coercing if possible.19 *20 * For example, "true" and true will match because the string value can be coerced into a valid boolean.21 * Similarly, "100" and 100 will match as the former can be coerced into an int.22 */23 @Deprecated(24 "Json comparison options is now specified with `CompareJsonOptions`",25 ReplaceWith("TypeCoercion.Enabled")26 )27 Lenient,28}29@Deprecated("Json comparison options is now specified with `CompareJsonOptions`", ReplaceWith("PropertyOrder"))30enum class CompareOrder {31 /**32 * All object properties must be in same order as expected.33 *34 * For example, { "x": 14.2, "y": 13.0 }` and `{ "y": 13.0, "x: 14.2 }` will NOT be considered equal.35 */36 @Deprecated(37 "Json comparison options is now specified with `CompareJsonOptions`",38 ReplaceWith("PropertyOrder.Strict")39 )40 Strict,41 @Deprecated(42 "Json comparison options is now specified with `CompareJsonOptions`",43 ReplaceWith("PropertyOrder.Lenient")44 )45 Lenient,46}47/**48 * helper method for bridging old compare options into new49 */50internal fun legacyOptions(mode: CompareMode, order: CompareOrder) =51 compareJsonOptions {52 typeCoercion = when (mode) {53 CompareMode.Strict -> TypeCoercion.Disabled54 CompareMode.Lenient -> TypeCoercion.Enabled55 }56 propertyOrder = when (order) {57 CompareOrder.Strict -> PropertyOrder.Strict58 CompareOrder.Lenient -> PropertyOrder.Lenient59 }60 }61internal val defaultCompareJsonOptions = CompareJsonOptions()62class CompareJsonOptions(63 /**64 * Controls whether property order must be identical65 */66 var propertyOrder: PropertyOrder = PropertyOrder.Lenient,67 /**68 * Controls whether array ordering must be identical.69 */70 var arrayOrder: ArrayOrder = ArrayOrder.Strict,71 /**72 * Controls whether the actual document may contain extra fields or not.73 */74 var fieldComparison: FieldComparison = FieldComparison.Strict,75 /**76 * Controls whether number formatting should be taken into consideration. For instance, comparing 1.00 to 1.0, or77 * 1E2 to 10078 */79 var numberFormat: NumberFormat = NumberFormat.Lenient,80 /**81 * Controls whether types should be coerced when possible. For instance, when strings contain bool or numeric values.82 */83 var typeCoercion: TypeCoercion = TypeCoercion.Disabled84)85enum class PropertyOrder {86 /**87 * Default. Property order in objects does not matter.88 *89 * Example: `"""{ "a": 0, "b": 2 }""".shouldEqualJson("""{ "b": 2, "a": 1 }""", compareJsonOptions { propertyOrder = Lenient })` will pass90 */91 Lenient,92 /**93 * Properties must be in same order. E.g. `{ "a": 0, "b": 2 }` is not considered equal to `{ "b": 2, "a": 1 }`94 */95 Strict96}97enum class ArrayOrder {98 /**99 * Default. Arrays must contain the same elements in the same order.100 */101 Strict,102 /**103 * Arrays are allowed to be shuffled, but must still contain same items.104 */105 Lenient,106}107enum class FieldComparison {108 /**109 * Default. Objects in [expected] and [actual] must contain the same fields.110 */111 Strict,112 /**113 * Objects in the actual document may contain extraneous fields without causing comparison to fail.114 */115 Lenient,116}117enum class NumberFormat {118 /**119 * Default. Numbers will be interpreted before being compared. Meaning we can compare 0E3 to 1000 without fail120 */121 Lenient,122 /**123 * Numbers must also be formatted the same way to be considered equal.124 */125 Strict126}127enum class TypeCoercion {128 /**129 * Default. Types will not be converted. Meaning `"true"` and `true` are considered unequal.130 */131 Disabled,132 /**133 * Types may be coerced. Strings containing numbers will be considered equal to their numbers, and booleans in134 * strings will also be compared.135 *136 * For example: `"\"11\"".shouldEqualJson("12", compareJsonOptions { typeCoercion = TypeCoercion.Enabled })` will137 * succeed.138 */139 Enabled;140 internal fun isEnabled(): Boolean =141 this == Enabled142}143fun compareJsonOptions(builder: CompareJsonOptions.() -> Unit): CompareJsonOptions =144 CompareJsonOptions().apply(builder)145/**146 * Compares two json trees, returning a detailed error message if they differ.147 */148internal fun compare(149 path: List<String>,150 expected: JsonNode,151 actual: JsonNode,152 options: CompareJsonOptions153): JsonError? {154 return when (expected) {155 is JsonNode.ObjectNode -> when (actual) {156 is JsonNode.ObjectNode -> compareObjects(path, expected, actual, options)157 else -> JsonError.ExpectedObject(path, actual)158 }159 is JsonNode.ArrayNode -> when (actual) {160 is JsonNode.ArrayNode -> compareArrays(path, expected, actual, options)161 else -> JsonError.ExpectedArray(path, actual)162 }163 is JsonNode.BooleanNode -> compareBoolean(path, expected, actual, options)164 is JsonNode.StringNode -> compareString(path, expected, actual, options)165 is JsonNode.NumberNode -> compareNumbers(path, expected, actual, options)166 JsonNode.NullNode -> compareNull(path, actual)167 }168}169internal fun compareObjects(170 path: List<String>,171 expected: JsonNode.ObjectNode,172 actual: JsonNode.ObjectNode,173 options: CompareJsonOptions,174): JsonError? {175 if (FieldComparison.Strict == options.fieldComparison) {176 val keys1 = expected.elements.keys177 val keys2 = actual.elements.keys178 if (keys1.size < keys2.size) {179 val missing = keys2 - keys1180 return JsonError.ObjectMissingKeys(path, missing)181 }182 if (keys2.size < keys1.size) {183 val extra = keys1 - keys2184 return JsonError.ObjectExtraKeys(path, extra)185 }186 }187 // when using strict order mode, the order of elements in json matters, normally, we don't care188 when (options.propertyOrder) {189 PropertyOrder.Strict ->190 expected.elements.entries.withIndex().zip(actual.elements.entries).forEach { (e, a) ->191 if (a.key != e.value.key) return JsonError.NameOrderDiff(path, e.index, e.value.key, a.key)192 val error = compare(path + a.key, e.value.value, a.value, options)193 if (error != null) return error194 }195 PropertyOrder.Lenient ->196 expected.elements.entries.forEach { (name, e) ->197 val a = actual.elements[name] ?: return JsonError.ObjectMissingKeys(path, setOf(name))198 val error = compare(path + name, e, a, options)199 if (error != null) return error200 }201 }202 return null203}204internal fun compareArrays(205 path: List<String>,206 expected: JsonNode.ArrayNode,207 actual: JsonNode.ArrayNode,208 options: CompareJsonOptions,209): JsonError? {210 if (expected.elements.size != actual.elements.size)211 return JsonError.UnequalArrayLength(path, expected.elements.size, actual.elements.size)212 when (options.arrayOrder) {213 ArrayOrder.Strict -> {214 expected.elements.withIndex().zip(actual.elements.withIndex()).forEach { (a, b) ->215 val error = compare(path + "[${a.index}]", a.value, b.value, options)216 if (error != null) return error217 }218 }219 /**220 * In [ArrayOrder.Lenient], we try to allow array contents to be out-of-order.221 * We do this by searching for a match for each element in [actual], in the [expected] array,222 * flagging used matches so they can't be used twice. This will probably be slow for very big arrays.223 */224 ArrayOrder.Lenient -> {225 val consumedIndexes = BooleanArray(expected.elements.size) { false }226 fun availableIndexes() = consumedIndexes227 .mapIndexed { index, isConsumed -> if (!isConsumed) index else null }228 .filterNotNull()229 fun findMatchingIndex(element: JsonNode): Int? {230 for (i in availableIndexes()) {231 // Comparison with no error -> matching element232 val isMatch = compare(path + "[$i]", element, expected.elements[i], options) == null233 if (isMatch) {234 return i235 }236 }237 return null238 }239 for ((i, element) in actual.elements.withIndex()) {240 val match = findMatchingIndex(element)241 ?: return JsonError.UnequalArrayContent(path + "[$i]", expected, element)242 consumedIndexes[match] = true243 }244 }245 }246 return null247}248/**249 * When comparing a string, if the [mode] is [CompareMode.Lenient] we can convert the actual node to a string.250 */251internal fun compareString(252 path: List<String>,253 expected: JsonNode.StringNode,254 actual: JsonNode,255 options: CompareJsonOptions256): JsonError? {257 return when {258 actual is JsonNode.StringNode -> compareStrings(path, expected.value, actual.value)259 options.typeCoercion.isEnabled() -> when {260 actual is JsonNode.BooleanNode -> compareStrings(path, expected.value, actual.value.toString())261 actual is JsonNode.NumberNode && expected.contentIsNumber() -> compareNumberNodes(262 path,263 expected.toNumberNode(),264 actual265 )266 else -> JsonError.IncompatibleTypes(path, expected, actual)267 }268 else -> JsonError.IncompatibleTypes(path, expected, actual)269 }270}271internal fun compareStrings(path: List<String>, expected: String, actual: String): JsonError? {272 return when (expected) {273 actual -> null274 else -> JsonError.UnequalStrings(path, expected, actual)275 }276}277/**278 * When comparing a boolean, if the [mode] is [CompareMode.Lenient] and the actual node is a text279 * node with "true" or "false", then we convert.280 */281internal fun compareBoolean(282 path: List<String>,283 expected: JsonNode.BooleanNode,284 actual: JsonNode,285 options: CompareJsonOptions286): JsonError? {287 return when {288 actual is JsonNode.BooleanNode -> compareBooleans(path, expected.value, actual.value)289 options.typeCoercion.isEnabled() && actual is JsonNode.StringNode -> when (actual.value) {290 "true" -> compareBooleans(path, expected.value, true)291 "false" -> compareBooleans(path, expected.value, false)292 else -> JsonError.UnequalValues(path, expected, actual)293 }294 else -> JsonError.IncompatibleTypes(path, expected, actual)295 }296}297internal fun compareBooleans(path: List<String>, expected: Boolean, actual: Boolean): JsonError? {298 return when (expected) {299 actual -> null300 else -> JsonError.UnequalBooleans(path, expected, actual)301 }302}303private fun compareNumbers(304 path: List<String>,305 expected: JsonNode.NumberNode,306 actual: JsonNode,307 options: CompareJsonOptions308): JsonError? {309 return when (actual) {310 is JsonNode.NumberNode -> {311 when (options.numberFormat) {312 NumberFormat.Strict -> {313 if (expected.content != actual.content) JsonError.UnequalValues(path, expected.content, actual.content)314 else null315 }316 NumberFormat.Lenient -> compareNumberNodes(path, expected, actual)317 }318 }319 is JsonNode.StringNode -> {320 if (options.typeCoercion.isEnabled() && actual.contentIsNumber()) compareNumberNodes(321 path,...

Full Screen

Full Screen

JsonLiteralsTest.kt

Source:JsonLiteralsTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.tests.json2import io.kotest.assertions.json.NumberFormat3import io.kotest.assertions.json.TypeCoercion4import io.kotest.assertions.json.compareJsonOptions5import io.kotest.assertions.json.shouldEqualJson6import io.kotest.assertions.shouldFail7import io.kotest.assertions.throwables.shouldThrow8import io.kotest.core.spec.style.FunSpec9import io.kotest.matchers.string.shouldContain10import io.kotest.matchers.throwable.shouldHaveMessage11class JsonLiteralsTest : FunSpec(12 {13 test("Unsupported type") {14 shouldThrow<IllegalArgumentException> {15 "0x03" shouldEqualJson "0x03"16 }.shouldHaveMessage("Unsupported kotlinx-serialization type 0x03")17 }18 context("Strict (default) comparisons") {19 test("comparing float and int") {20 shouldFail {21 "3.2" shouldEqualJson "3"22 }.shouldHaveMessage(23 """24 The top level expected 3 but was 3.225 expected:<3> but was:<3.2>26 """.trimIndent()27 )28 }29 test("quoted numbers are treated as strings") {30 shouldFail { "\"1E3\"" shouldEqualJson "1000.0" }31 // Unquoted 1E3 is parsed to double and back due to prettifying output32 shouldFail { "\"1000.0\"" shouldEqualJson "1E3" }.message shouldContain33 "The top level expected number but was string"34 shouldFail { "10.0" shouldEqualJson "\"10.0\"" }.message shouldContain35 "The top level expected string but was number"36 }37 test("comparing exponent-based float with regular float") {38 "1E3" shouldEqualJson "1000.0"39 "1000.0" shouldEqualJson "1E3"40 "1000.0" shouldEqualJson "1000"41 "5E0" shouldEqualJson "5.0"42 "2E-1" shouldEqualJson "0.2"43 shouldFail {44 "1.0E-3" shouldEqualJson "0.0001"45 }46 "1.0E-4" shouldEqualJson "0.0001"47 }48 test("comparing high-precision floating point numbers") {49 // Note: In the middle paragraph of the failure message the expected JSON has been50 // formatted as a JSON tree using KotlinX.serialization which parses the51 // number to a double and back, hence the loss of precision.52 shouldFail {53 "0.12345678912345678" shouldEqualJson "0.123456789123456789"54 }.shouldHaveMessage(55 """56 The top level expected 0.123456789123456789 but was 0.1234567891234567857 expected:<0.123456789123456789> but was:<0.12345678912345678>58 """.trimIndent()59 )60 }61 test("comparing string and boolean") {62 shouldFail {63 "true" shouldEqualJson "\"true\""64 }.shouldHaveMessage(65 """66 The top level expected string but was boolean67 expected:<"true"> but was:<true>68 """.trimIndent()69 )70 }71 }72 context("CompareMode.Exact requires same format for numbers") {73 infix fun String.shouldExactlyEqualJson(expected: String) =74 this.shouldEqualJson(expected, compareJsonOptions { numberFormat = NumberFormat.Strict })75 test("comparing float and exponent") {76 shouldFail {77 "10.0" shouldExactlyEqualJson "1e1"78 }.shouldHaveMessage(79 """80 The top level expected 1e1 but was 10.081 expected:<1e1> but was:<10.0>82 """.trimIndent()83 )84 }85 test("comparing int and exponent") {86 shouldFail {87 "10" shouldExactlyEqualJson "1e1"88 }.shouldHaveMessage(89 """90 The top level expected 1e1 but was 1091 expected:<1e1> but was:<10>92 """.trimIndent()93 )94 }95 test("comparing float and int") {96 shouldFail {97 "10.0" shouldExactlyEqualJson "10"98 }.shouldHaveMessage(99 """100 The top level expected 10 but was 10.0101 expected:<10> but was:<10.0>102 """.trimIndent()103 )104 }105 test("quoted numbers are treated as strings") {106 shouldFail { "\"1E3\"" shouldEqualJson "1000.0" }107 // Unquoted 1E3 is parsed to double and back due to prettifying output108 shouldFail { "\"1000.0\"" shouldEqualJson "1E3" }.message shouldContain109 "The top level expected number but was string"110 shouldFail { "10.0" shouldEqualJson "\"10.0\"" }.message shouldContain111 "The top level expected string but was number"112 }113 }114 context("Lenient type-conversions") {115 infix fun String.lenientShouldEqualJson(expected: String) =116 this.shouldEqualJson(expected, compareJsonOptions { typeCoercion = TypeCoercion.Enabled })117 test("comparing exponent-based float with regular float") {118 "1E3" lenientShouldEqualJson "\"1000.0\""119 "1000.0" lenientShouldEqualJson "\"1E3\""120 "2E-1" lenientShouldEqualJson "0.2"121 "2E-1" lenientShouldEqualJson "\"0.2\""122 "0.2" lenientShouldEqualJson "\"2e-1\""123 "5E0" lenientShouldEqualJson "5.0"124 }125 test("Strings with numbers") {126 shouldFail {127 "\"abc 123\"" lenientShouldEqualJson "123"128 }.shouldHaveMessage(129 """130 The top level expected number but was string131 expected:<123> but was:<"abc 123">132 """.trimIndent()133 )134 shouldFail {135 "123" lenientShouldEqualJson "\"abc 123\""136 }137 }138 test("booleans in strings are ok") {139 "true" lenientShouldEqualJson "\"true\""140 "\"true\"" lenientShouldEqualJson "true"141 }142 test("float and int can be mixed, if exactly same") {143 "1.0" lenientShouldEqualJson "1"144 "1" lenientShouldEqualJson "1.0"145 }146 test("Dont trim necessary zeroes") {147 shouldFail {148 "10" lenientShouldEqualJson "1.0"149 }150 shouldFail {151 "1" lenientShouldEqualJson "10.0"152 }153 }154 test("high-precision float with only trailing zeros") {155 "1" lenientShouldEqualJson "1.0000000000000000000000000"156 "1.0000000000000000000000000" lenientShouldEqualJson "1"157 }158 }159 }160)...

Full Screen

Full Screen

JsonMatchers.kt

Source:JsonMatchers.kt Github

copy

Full Screen

...98 *99 */100fun String.shouldEqualJson(expected: String, mode: CompareMode, order: CompareOrder) =101 this.shouldEqualJson(expected, legacyOptions(mode, order))102fun String.shouldEqualJson(expected: String, options: CompareJsonOptions) {103 val (e, a) = parse(expected, this)104 a should equalJson(e, options)105}106fun String.shouldNotEqualJson(expected: String, mode: CompareMode, order: CompareOrder) =107 this.shouldNotEqualJson(expected, legacyOptions(mode, order))108fun String.shouldNotEqualJson(expected: String, options: CompareJsonOptions) {109 val (e, a) = parse(expected, this)110 a shouldNot equalJson(e, options)111}112fun String.shouldBeEmptyJsonArray(): String {113 this should matchJson("[]")114 return this115}116fun String.shouldBeEmptyJsonObject(): String {117 this should matchJson("{}")118 return this119}120fun String.shouldBeJsonArray(): String {121 this should beJsonType(JsonArray::class)122 return this...

Full Screen

Full Screen

LenientOrderArrayTest.kt

Source:LenientOrderArrayTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.tests.json2import io.kotest.assertions.json.ArrayOrder3import io.kotest.assertions.json.compareJsonOptions4import io.kotest.assertions.json.shouldEqualJson5import io.kotest.assertions.shouldFail6import io.kotest.core.spec.style.FunSpec7import io.kotest.matchers.throwable.shouldHaveMessage8class LenientOrderArrayTest : FunSpec(9 {10 infix fun String.shouldEqualJsonIgnoringOrder(other: String) =11 this.shouldEqualJson(other, compareJsonOptions { arrayOrder = ArrayOrder.Lenient })12 test("simple") {13 "[1, 2]" shouldEqualJsonIgnoringOrder "[2, 1]"14 }15 test("multiple copies") {16 "[1, 2, 2]" shouldEqualJsonIgnoringOrder "[2, 1, 2]"17 }18 test("duplicates in actual") {19 shouldFail {20 "[1, 2, 2]" shouldEqualJsonIgnoringOrder "[1, 2, 0]"21 }.shouldHaveMessage(22 """23 At '[2]' has extra element '2' not found (or too few) in '[1,2,0]'24 expected:<[25 1,26 2,27 028 ]> but was:<[29 1,30 2,31 232 ]>33 """.trimIndent()34 )35 }36 test("array with objects in different order") {37 val a = """38 {39 "someList": [40 {41 "type": "SOME_TYPE_2"42 },43 {44 "type": "SOME_TYPE_1"45 }46 ]47 }48 """49 val b = """50 {51 "someList": [52 {53 "type": "SOME_TYPE_1"54 },55 {56 "type": "SOME_TYPE_2"57 }58 ]59 }60 """61 a shouldEqualJsonIgnoringOrder b62 }63 test("array of objects - missing object") {64 val a = """65 {66 "someList": [67 {68 "type": "SOME_TYPE_2"69 },70 {71 "type": "SOME_TYPE_1"72 },73 {74 "type": "SOME_TYPE_3"75 }76 ]77 }78 """79 val b = """80 {81 "someList": [82 {83 "type": "SOME_TYPE_1"84 },85 {86 "type": "SOME_TYPE_2"87 },88 {89 "type": "SOME_TYPE_2"90 }91 ]92 }93 """94 shouldFail {95 a shouldEqualJsonIgnoringOrder b96 }.shouldHaveMessage(97 """98 At 'someList.[2]' has extra element '{"type": SOME_TYPE_3}' not found (or too few) in '[{"type": SOME_TYPE_1},{"type": SOME_TYPE_2},{"type": SOME_TYPE_2}]'99 expected:<{100 "someList": [101 {102 "type": "SOME_TYPE_1"103 },104 {105 "type": "SOME_TYPE_2"106 },107 {108 "type": "SOME_TYPE_2"109 }110 ]111 }> but was:<{112 "someList": [113 {114 "type": "SOME_TYPE_2"115 },116 {117 "type": "SOME_TYPE_1"118 },119 {120 "type": "SOME_TYPE_3"121 }122 ]123 }>124 """.trimIndent()125 )126 }127 }128)...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...21 order: CompareOrder,22) = equalJson(expected, legacyOptions(mode, order))23fun equalJson(24 expected: JsonTree,25 options: CompareJsonOptions26) =27 object : Matcher<JsonTree> {28 override fun test(value: JsonTree): MatcherResult {29 val error = compare(30 path = listOf(),31 expected = expected.root,32 actual = value.root,33 options,34 )?.asString()35 return ComparableMatcherResult(36 error == null,37 { "$error\n\n" },38 { "Expected values to not match\n\n" },39 value.raw,40 expected.raw,41 )42 }43 }44data class JsonTree(val root: JsonNode, val raw: String)45infix fun String.shouldEqualJson(expected: String): Unit =46 this.shouldEqualJson(expected, defaultCompareJsonOptions)47infix fun String.shouldNotEqualJson(expected: String): Unit =48 this.shouldNotEqualJson(expected, defaultCompareJsonOptions)49fun String.shouldEqualJson(expected: String, mode: CompareMode) =50 shouldEqualJson(expected, legacyOptions(mode, CompareOrder.Strict))51fun String.shouldNotEqualJson(expected: String, mode: CompareMode) =52 shouldNotEqualJson(expected, legacyOptions(mode, CompareOrder.Strict))53fun String.shouldEqualJson(expected: String, order: CompareOrder) =54 shouldEqualJson(expected, legacyOptions(CompareMode.Strict, order))55fun String.shouldNotEqualJson(expected: String, order: CompareOrder) =56 shouldNotEqualJson(expected, legacyOptions(CompareMode.Strict, order))57infix fun String.shouldEqualSpecifiedJson(expected: String) =58 shouldEqualJson(expected, compareJsonOptions { fieldComparison = FieldComparison.Lenient })59infix fun String.shouldNotEqualSpecifiedJson(expected: String) =60 shouldNotEqualJson(expected, compareJsonOptions { fieldComparison = FieldComparison.Lenient })...

Full Screen

Full Screen

CompareJsonOptions

Using AI Code Generation

copy

Full Screen

1val expectedJson = """{ "name": "John", "age": 30 }"""2val actualJson = """{ "name": "John", "age": 30 }"""3CompareJsonOptions.ignoreExtraActualKeys.compareJson(expectedJson, actualJson)4val expectedJson = """{ "name": "John", "age": 30 }"""5val actualJson = """{ "name": "John", "age": 32 }"""6CompareJsonOptions.ignoreExtraActualKeys.compareJson(expectedJson, actualJson)7val expectedJson = """{ "name": "John", "age": 30 }"""8val actualJson = """{ "name": "John", "age": 30, "city": "New York" }"""9CompareJsonOptions.ignoreExtraActualKeys.compareJson(expectedJson, actualJson)10val expectedJson = """{ "name": "John", "age": 30 }"""11val actualJson = """{ "name": "John", "age": 30, "city": "New York" }"""12CompareJsonOptions.ignoreExtraActualKeys.compareJson(expectedJson, actualJson)13val expectedJson = """{ "name": "John", "age": 30 }"""14val actualJson = """{ "name": "John", "age": 30, "city": "New York" }"""15CompareJsonOptions.ignoreExtraActualKeys.compareJson(expectedJson, actualJson)16val expectedJson = """{ "name": "John", "age": 30 }"""17val actualJson = """{ "name": "John", "age": 30, "city": "New York" }"""18CompareJsonOptions.ignoreExtraActualKeys.compareJson(expectedJson, actualJson)19val expectedJson = """{ "name": "John", "age": 30 }"""20val actualJson = """{ "name": "John", "age": 30, "city":

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful