Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Fix flaky test testParamsByNameUnmatchedMessage() #1

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

Conversation

anirudh711
Copy link

PR Overview

The PR proposes a fix for the following tests -
net.ttddyy.dsproxy.asserts.hamcrest.ParameterHolderAssertionsTest#testParamsByNameUnmatchedMessage

Build Project

  • To build the project :
mvn clean install
  • To run the test :
mvn test
  • To run the nondex tool on this test :
mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=<path.to.test#testName>

Problem

This flakiness was identified by the nondex tool created by the researchers of UIUC. The above eight tests fail when run on the nondex tool.
This test uses a map with keys foo and bar and is being asserted that the order must be with keys bar and foo. Simply changing the order of insertion of the map values will not solve this since the map still does not maintain order of insertion and there are possibilities this can fail again in the same way

Map<String, Object> map = new HashMap<>();
map.put("foo", 100);
map.put("bar", 200);
ParameterByNameHolder holder = mock(ParameterByNameHolder.class);
given(holder.getSetParamsByName()).willReturn(map);
try {
Assert.assertThat(holder, paramsByName(hasEntry("BAZ", (Object) 10)));
fail("asserts should fail");
} catch (AssertionError e) {
assertThat(e).hasMessage("\nExpected: parameters as a map containing [\"BAZ\"-><10>]\n but: map was [<bar=200>, <foo=100>]");
}

Fix:

The proposed fix is to use a LinkedHashMap instead of a map since it will maintain the order of insertion

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant