Skip to content
Advertisement

JUnit5 test void method. Get org.opentest4j.AssertionFailedError: expected:

Don’t judge my code, I am beginner. In the future, I’ll refactor it.

I would like to ask for help writing JUnit5 unit tests.

I need to test my class Formatter

JavaScript

The main task of the class is to print the result of long division

Something like this

JavaScript

I wrote a test

JavaScript

My test throws an error but outputs what is displayed is what it expects

JavaScript

When I click I see message “contents are identical” enter image description here I can’t understand why it throws an error if contents are identical

Please share your ideas of what it could be

Is there some way to replace rn to n?

Thank you in advance!

Advertisement

Answer

I solved my problem by putting the expected result in file result.xml

JavaScript

And add this in my test case

JavaScript

Also helped to change all System.out.println to System.out.printf and

JavaScript
Advertisement