Skip to content

test: pin that user messages containing "expected" survive in full - #47

Open
Contributerr27 wants to merge 1 commit into
testng-team:mainfrom
Contributerr27:test/message-preservation-gh16
Open

Contributerr27 wants to merge 1 commit into
testng-team:mainfrom
Contributerr27:test/message-preservation-gh16

Conversation

@Contributerr27

Copy link
Copy Markdown

Closes #16

What

Adds MessagePreservationTest (10 tests) pinning that a user-supplied description survives intact in the thrown AssertionError for every hard assert shape (assertTrue/assertFalse/assertEquals/assertNotEquals/assertNull/assertNotNull), for fail(...), and for the SoftAssert aggregation path. Two of the ten cover the worst cases from #16: the issue's exact message (Text is not expected. It should be this) and a message that mimics the expected: <x> but was: <y> comparison pattern.

Why

#16 reported a description shown only up to the word "expected". That symptom came from the pre-AssertJ message construction. The current asserts delegate to AssertJ (assertTrue -> assertThat(condition).as(message).isTrue()), and the user text now reaches the exception in full. Verified against AssertJ 3.27.7:

assertTrue(false, "Text is not expected. It should be this");
// AssertionError.getMessage() ==
// "[Text is not expected. It should be this] \nExpecting value to be true but was false"

What a runner or IDE displays is its own pattern-matching, but the exception message itself (what Surefire reports and what IntelliJ receives) carries everything, so the behavior the issue asks for is in place. These tests pin it so it can't silently regress.

Testing

mvn test -> 214 tests run, 0 failures, 0 errors (10 new).

Regression coverage for testng-team#16. The reported symptom (a message like "Text is not expected. It should be this" displayed only up to "expected") came from the pre-AssertJ message construction. With the current AssertJ-backed asserts the user text reaches the caller intact, and these tests pin that for the hard asserts, fail(), and the SoftAssert aggregation path, including a message that mimics the "expected: <x> but was: <y>" comparison pattern that test runners pattern-match.

Closes testng-team#16
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.

Assertion message is displayed only until the "expected" keyword

1 participant