Comparing two XML strings/files in Groovy/Java

后端 未结 3 1244
执念已碎
执念已碎 2020-12-31 15:36

I\'m writing unit tests for checking some XML builder.

Now I\'m running into the problem of syntactical differences between the expected result and the actual result

3条回答
  •  Happy的楠姐
    2020-12-31 15:44

    Older question, but maybe interesting for future use.
    Another possibility, that works not only for XML, but could also be used for your problem.

    For Tests like this, you could also use use ApprovalTests (http://approvaltests.sourceforge.net), which results in very little code in your unit test.

    With ApprovalTests you write your test and check your output with the expected output.

    Short description: In the first run of your test, there is no expected output, so ApprovalTests writes two files - a "received" (output of your code) and "approved" (expected output of your code). In the first run, the "approved" is empty, because you have to approve the output of your code. This is done with a diff tool. ApprovalTests opens a diff tool and shows the two files in it. If the output of your code is what you expected, you move the output to the approved file. Now all subsequent tests runs will pass, if the output does not change (received == approved).

提交回复
热议问题