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

Improved execution of grouped assertions #1674

Merged
merged 2 commits into from Mar 31, 2021

Conversation

eas5
Copy link

@eas5 eas5 commented Mar 24, 2021

Problem:
A test method with many individual assertions stops being executed on the first failed assertion, which prevents the remaining ones' execution.

Solution:
Using the soft assertions feature, all assertions are executed, and all failures will be reported together. In this refactoring, no original assertion was changed.

Result:
Before:

assertThat(app.getManagementUrl()).isEqualTo("http://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("http://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("http://application/Uppercase/");

After:

SoftAssertions softly = new SoftAssertions();
softly.assertThat(app.getManagementUrl()).isEqualTo("http://application/Uppercase/actuator");
softly.assertThat(app.getHealthUrl()).isEqualTo("http://application/Uppercase/actuator/health");
softly.assertThat(app.getServiceUrl()).isEqualTo("http://application/Uppercase/");
softly.assertAll();

Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>
@erikpetzold
Copy link
Member

Hi @eas5 , thanks for your contribution. As you may have seen in the build result, we want to use only assertj assertions to have consistency across all tests.
The equivalent to your changes would be SoftAssertions.assertSoftly: https://assertj.github.io/doc/#assertj-core-assertSoftly-assertions

Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>
@eas5
Copy link
Author

eas5 commented Mar 31, 2021

Hi @erikpetzold! Thank you for your instruction. I have changed my proposal to use Assertj's SoftAssertions.

@ccoltx ccoltx merged commit 5dde24d into codecentric:master Mar 31, 2021
@ccoltx ccoltx added this to the 2.4.1 milestone Mar 31, 2021
@ccoltx
Copy link
Contributor

ccoltx commented Mar 31, 2021

Hi @eas5, thank you for your contribution.

SteKoe added a commit to ParkerM/spring-boot-admin that referenced this pull request Apr 16, 2021
…-relpaths

* origin/master:
  Add retry on failing subscription (codecentric#1697)
  chore(deps): update dependency pl.project13.maven:git-commit-id-plugin to v4.0.4 (codecentric#1663)
  chore(deps): update dependency com.puppycrawl.tools:checkstyle to v8.41.1 (codecentric#1648)
  Fix for codecentric#1638 (codecentric#1673)
  Improve npm ci build times (see codecentric#1688) (codecentric#1689)
  Improved execution of grouped assertions (codecentric#1674)
  Use maven repo cache during publish snapshots (codecentric#1687)
  chore(deps): update metcalfc/changelog-generator action to v1 (codecentric#1669)
  chore(deps): update dependency org.codehaus.mojo:flatten-maven-plugin to v1.2.7 (codecentric#1686)
  Fix file formating by applying spring-javaformat:apply (codecentric#1685)
  Cache mvn repo in main build (see codecentric#1677 ) (codecentric#1678)
  Added support DingTalk notifier. (codecentric#1653)
  Simplify some code (codecentric#1670)
  Bugfix/1646 (codecentric#1661)
  Upgrade spring cloud dependencies (codecentric#1645)
  chore(deps): update dependency com.github.eirslett:frontend-maven-plugin to v1.11.2 (codecentric#1635)
  chore(deps): update spring boot to v2.4.3 (codecentric#1637)
  Bump version to 2.4.1-SNAPSHOT
  chore(deps): update testcontainers.version to v1.15.2 (codecentric#1629)
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.

None yet

3 participants