Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Fix: Fix tests that can unintentionally fail in toXMLIncludesAllElements() and serializesPriorAuthenticationDetails() due to local time conversion #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jake-WangZhi
Copy link

The actual date in the output has been converted to the local time zone when compared to the expected date. As a result, these tests can fail depending on where they are run.

Below are examples where it fails under NonDex on line 49 in TransactionIndustryRequestTest.java and on line 235 in ThreeDSecureLookupRequestTest.java
(My timezone is CDT)

Click on to see more details on the error message when running both tests
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.braintreegateway.unittest.TransactionIndustryRequestTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.438 s <<< FAILURE! - in com.braintreegateway.unittest.TransactionIndustryRequestTest
[ERROR] toXMLIncludesAllElements  Time elapsed: 0.397 s  <<< ERROR!
junit.framework.AssertionFailedError: 
org.custommonkey.xmlunit.Diff
[not identical] Expected sequence of child nodes '1' but was '3' - comparing <arrivalDate...> at /industry[1]/data[1]/arrivalDate[1] to <arrivalDate...> at /industry[1]/data[1]/arrivalDate[1]

[different] Expected text value '2023-02-10T22:45:30Z' but was '2023-02-11T04:45:30Z' - comparing <arrivalDate ...>2023-02-10T22:45:30Z</arrivalDate> at /industry[1]/data[1]/arrivalDate[1]/text()[1] to <arrivalDate ...>2023-02-11T04:45:30Z</arrivalDate> at /industry[1]/data[1]/arrivalDate[1]/text()[1]

        at com.braintreegateway.unittest.TransactionIndustryRequestTest.toXMLIncludesAllElements(TransactionIndustryRequestTest.java:49)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   TransactionIndustryRequestTest.toXMLIncludesAllElements:49 org.custommonkey.xmlunit.Diff
[not identical] Expected sequence of child nodes '1' but was '3' - comparing <arrivalDate...> at /industry[1]/data[1]/arrivalDate[1] to <arrivalDate...> at /industry[1]/data[1]/arrivalDate[1]

[different] Expected text value '2023-02-10T22:45:30Z' but was '2023-02-11T04:45:30Z' - comparing <arrivalDate ...>2023-02-10T22:45:30Z</arrivalDate> at /industry[1]/data[1]/arrivalDate[1]/text()[1] to <arrivalDate ...>2023-02-11T04:45:30Z</arrivalDate> at /industry[1]/data[1]/arrivalDate[1]/text()[1]

[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.braintreegateway.unittest.ThreeDSecureLookupRequestTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.295 s <<< FAILURE! - in com.braintreegateway.unittest.ThreeDSecureLookupRequestTest
[ERROR] serializesPriorAuthenticationDetails  Time elapsed: 0.275 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
        at com.braintreegateway.unittest.ThreeDSecureLookupRequestTest.serializesPriorAuthenticationDetails(ThreeDSecureLookupRequestTest.java:235)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   ThreeDSecureLookupRequestTest.serializesPriorAuthenticationDetails:235 expected: <true> but was: <false>
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]

To reproduce both, run these at the root directory:

mvn edu.illinois:nondex-maven-plugin:2.1.7:nondex     -Dtest=com/braintreegateway/unittest/TransactionIndustryRequestTest#toXMLIncludesAllElements
mvn edu.illinois:nondex-maven-plugin:2.1.7:nondex     -Dtest=com/braintreegateway/unittest/ThreeDSecureLookupRequestTest#serializesPriorAuthenticationDetails

The log output for both tests can be found here for your reference:
mvn-nondex-2-1729185623.log
mvn-nondex-1729184306.log

To resolve this, we need to ensure that the conversion to the local time zone doesn't occur when comparing with the expected date. To achieve this, we can explicitly set the Calendar's time zone to UTC.

After applying the fix, the test should now pass with NonDex as expected:

[INFO] *********
[INFO] All tests pass without NonDex shuffling
[INFO] ####################
[INFO] Across all seeds:
[INFO] Test results can be found at: 
[INFO] file:///home/jakew4/braintree_java/.nondex/o+N2zAWYfjR4hoCKwtDY9gT7hwenXEQae4EH6eFm3FA=/test_results.html
[INFO] [NonDex] The id of this run is: o+N2zAWYfjR4hoCKwtDY9gT7hwenXEQae4EH6eFm3FA=
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.764 s
[INFO] Finished at: 2024-10-17T12:29:20-05:00
[INFO] ------------------------------------------------------------------------

Please let me know if this approach works for you. If not, I'm happy to discuss alternatives and am willing to spend more time to address the test in the way you'd prefer. Thank you!

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.

1 participant