Skip to content

Integration test JSON comparison system#79

Merged
timkimadobe merged 31 commits intoadobe:feature/integration-testsfrom
timkimadobe:integration-test-json-comparison
Sep 6, 2023
Merged

Integration test JSON comparison system#79
timkimadobe merged 31 commits intoadobe:feature/integration-testsfrom
timkimadobe:integration-test-json-comparison

Conversation

@timkimadobe
Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe commented Aug 8, 2023

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 uses JSONObject and JSONArray from the org.json package.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 8, 2023

Codecov Report

Merging #79 (3af325e) into feature/integration-tests (6483999) will not change coverage.
The diff coverage is n/a.

@@                     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           
Flag Coverage Δ
functional-tests 66.18% <ø> (ø)
unit-tests 79.65% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

dependencies {
implementation project(':edge')
implementation "com.adobe.marketing.mobile:core:${rootProject.mavenCoreVersion}"
implementation "androidx.test.ext:junit:${rootProject.ext.junitVersion}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the Junit libraries needed under implementation or only testImplementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some direct assertions in the comparison code itself which require it in the implementation

Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some direct assertions in the comparison code itself which require it in the implementation

expected = expected.opt(key),
actual = actual.opt(key),
keyPath = keyPath,
pathTree = null, // is String means path terminates here
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "null String means path.." ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidated the logic here, hopefully it is more clear!

Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Consistency of param descriptions across methods
  2. Consistency of code/class styling
  3. Descriptions of methods, especially the public ones

expected = expected.opt(key),
actual = actual.opt(key),
keyPath = keyPath,
pathTree = null, // is String means path terminates here
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidated the logic here, hopefully it is more clear!

}

@Test
fun `test special key name trailing period`() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Update wildcard matching docs
Remove redundant test cases from JSONAssertsTests, simplify cases based on already covered logic
Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

}

@Test
fun `test special key name trailing period`() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}

@Test
fun `test special key name trailing period`() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @emdobrin! Updated based on feedback with some outstanding questions, please let me know what you think

@timkimadobe timkimadobe merged commit ad87367 into adobe:feature/integration-tests Sep 6, 2023
@timkimadobe timkimadobe deleted the integration-test-json-comparison branch September 6, 2023 01:24
@timkimadobe timkimadobe linked an issue Sep 8, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JSON comparison assert helpers

4 participants