How to Fix “junit.framework.Comparison Failure Expected: but was”

junit.framework.ComparisonFailure: expected:< . > But was: solution

an error occurred while running the MVN instruction: MVN clean test using the DOS window:

[ERROR] Please refer to D:\ learning gadgets \ first semester of junior \ enterprise application construction and management \ experiments \maven_demo\target\surefire-reports for the individual test results

error display from the surefire – reports file to find errors, check the surefire – reports file:

error body is this:
junit.framework.ComparisonFailure: expected:< Hello [World]guoyilin! > but was:< Hello []guoyilin! >

in the test file called assetEquals method, the method to compare the the statement with a specified in parentheses, if different than the error


you can see, The statement returned in the sayHello method is different from the statement specified in the test module, and that’s where the error is, just change the statement to be the same.

Read More: