newline after Mockito verify call fails the test
hi,
im trying to verify a logger method call with this code line:
when i execute the test it fails due to a "Comparison" error
comparing the expected
to the actual:
shows the difference is after the codeline has ended (notice the newline after the "Actual" value)(i put a \n to help visualize it since three backtick syntax would remove trailing newlines)
How can i include that newline into the "expected"?
Or tell Mockito to ignore the trailing newline?
10 Replies
⌛
This post has been reserved for your question.
Hey @SterniXPutzig! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
That's probably not what's happening.
when i click on <Click to see difference> (difference between expected and actual) it shows me this (the only difference is the newline at the end of the actual value)

Erm. Kinda make me want to ask see difference between what and and what
So you're testing that some data sent is some Java code of logging something?
Your original example says that you're testing for
some text {}
the screenshot just shows how mockito displays the difference between the 2
in the code i do this:
and in the test Method i have this configuration:
basically the arguments are identical but mockito adds a newline after the code line when it is being logged by mockito
Mockito doesn't log things
There is a newline when you do the real code. If you don't expect it, then either you should expect it, or your actual code adds a newline that you want that it doesn't add
What may happen and not be made obvious by the comparison though, is that the new line is not in expected format. I'd encourage you to run debug and to check the exact content of the String
My Problem is
How do I change this line:
To expect a newline after the semicolon?
Because the arguments themselves are correct
No, you need someArg to contain the newline too
nope then it has 2 mismatched positions:
-after someArg because the newline is expected but not present
-after the semicolon because no newline is expected but is present
im creating a minimal working example atm
Post Closed
This post has been closed by <@378591387341291520>.