Integration test JSON comparison system#79
Conversation
Slight logical errors and mutability
…blic methods Add initial unit test cases for JSON comparison assertion methods
Codecov Report
@@ Coverage Diff @@
## feature/integration-tests #79 +/- ##
============================================================
Coverage 83.63% 83.63%
Complexity 380 380
============================================================
Files 29 29
Lines 1582 1582
Branches 225 225
============================================================
Hits 1323 1323
Misses 162 162
Partials 97 97
Flags with carried forward coverage won't be shown. Click here to find out more. |
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
...tests/src/androidTest/java/com/adobe/marketing/mobile/integration/ExampleInstrumentedTest.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONObjectAssertsTests.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
| dependencies { | ||
| implementation project(':edge') | ||
| implementation "com.adobe.marketing.mobile:core:${rootProject.mavenCoreVersion}" | ||
| implementation "androidx.test.ext:junit:${rootProject.ext.junitVersion}" |
There was a problem hiding this comment.
Are the Junit libraries needed under implementation or only testImplementation?
There was a problem hiding this comment.
There are some direct assertions in the comparison code itself which require it in the implementation
Update comparison logic
Remove extra newlines in assertion logging
Refactor alternate path array access handling and add corresponding test cases
timkimadobe
left a comment
There was a problem hiding this comment.
Thanks @kevinlind and @emdobrin for the review! Updated based on feedback
| dependencies { | ||
| implementation project(':edge') | ||
| implementation "com.adobe.marketing.mobile:core:${rootProject.mavenCoreVersion}" | ||
| implementation "androidx.test.ext:junit:${rootProject.ext.junitVersion}" |
There was a problem hiding this comment.
There are some direct assertions in the comparison code itself which require it in the implementation
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONObjectAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONObjectAssertsTests.kt
Outdated
Show resolved
Hide resolved
...tests/src/androidTest/java/com/adobe/marketing/mobile/integration/ExampleInstrumentedTest.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
| expected = expected.opt(key), | ||
| actual = actual.opt(key), | ||
| keyPath = keyPath, | ||
| pathTree = null, // is String means path terminates here |
There was a problem hiding this comment.
typo: "null String means path.." ?
There was a problem hiding this comment.
Consolidated the logic here, hopefully it is more clear!
Replace all nil with null
timkimadobe
left a comment
There was a problem hiding this comment.
Thanks for the review @addb! Updated based on feedback
Also refactored some logic to simplify code paths and updated a lot of the method documentation to improve:
- Consistency of param descriptions across methods
- Consistency of code/class styling
- Descriptions of methods, especially the public ones
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
| expected = expected.opt(key), | ||
| actual = actual.opt(key), | ||
| keyPath = keyPath, | ||
| pathTree = null, // is String means path terminates here |
There was a problem hiding this comment.
Consolidated the logic here, hopefully it is more clear!
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| fun `test special key name trailing period`() { |
There was a problem hiding this comment.
since you are running same asserts for all these special characters I think you can write these as parameterized tests where you predefine the expected/actual values.
this will save some lines of code as well and show all the values tested in one place
There was a problem hiding this comment.
That sounds great! Updated to use parameterized tests for test cases where there was a lot of overlap in terms of setup. The current setup uses a larger class to hold the individual parameterized cases since Junit 4 only supports sending parameters to each test case. It also uses a test suite setup so all the individual parameterized test classes can be run at once
There was a problem hiding this comment.
wow, after these changes 1k lines were gone! 🎉
I left some comments on the ones that looked more intimidating, please review to see if they make sense to be kept in the expanded form.
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONAssertsTests.kt
Outdated
Show resolved
Hide resolved
Update wildcard matching docs
Update to test fail instead of print
Remove redundant test cases from JSONAssertsTests, simplify cases based on already covered logic
timkimadobe
left a comment
There was a problem hiding this comment.
Thank you for the review @emdobrin! Updated based on feedback, hopefully the parameterized tests help improve the readability. Please let me know what you think of the new test organization and logical coverage!
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Show resolved
Hide resolved
code/test-utils/src/main/java/com/adobe/marketing/tester/util/JSONAsserts.kt
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| fun `test special key name trailing period`() { |
There was a problem hiding this comment.
That sounds great! Updated to use parameterized tests for test cases where there was a lot of overlap in terms of setup. The current setup uses a larger class to hold the individual parameterized cases since Junit 4 only supports sending parameters to each test case. It also uses a test suite setup so all the individual parameterized test classes can be run at once
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONAssertsTests.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONAssertsParameterizedTests.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONAssertsParameterizedTests.kt
Show resolved
Hide resolved
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONAssertsParameterizedTests.kt
Outdated
Show resolved
Hide resolved
code/test-utils/src/test/java/com/adobe/marketing/tester/util/JSONAssertsTests.kt
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| fun `test special key name trailing period`() { |
There was a problem hiding this comment.
wow, after these changes 1k lines were gone! 🎉
I left some comments on the ones that looked more intimidating, please review to see if they make sense to be kept in the expanded form.
timkimadobe
left a comment
There was a problem hiding this comment.
Thanks for the review @emdobrin! Updated based on feedback with some outstanding questions, please let me know what you think
Description
This PR implements the JSON comparison system analogous to the version built in Edge iOS (adobe/aepsdk-edge-ios#332). Instead of
AnyCodable, this version usesJSONObjectandJSONArrayfrom theorg.jsonpackage.Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: