Skip to content

[Enhancement]: use testify's require instead of assert. #2808

@mdelapenya

Description

@mdelapenya

Proposal

TL;DR: use require when a failure should stop the test completely, ensuring that subsequent steps are not executed with invalid assumptions. Use assert when we want to evaluate all assertions, even if some fail, to provide more comprehensive feedback on test results.

Why?

By using require for crucial checks, we can avoid misleading error messages from failed assertions that come later in the test after an essential condition has already failed. This makes the root cause of the failure easier to diagnose, as the test execution halts as soon as the condition fails, preventing further unnecessary execution of test logic that depends on the success of the failed condition. This can save time, especially in long or complex tests, where subsequent steps may not be relevant after a failure.

assert, on the other hand, might allow tests to continue, resulting in multiple failures and potentially obscuring the real cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueWant to contribute to testcontainers? Start from herehacktoberfestPull Requests accepted for Hacktoberfest.low hanging fruitIssues that are good for newcomers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions