java - What are alternatives to JUnit's assertEquals() method in order to see in the test report which fields of objects differed on comparison? -


i have lot of automated tests written in java on junit , use assertequals(java.lang.string message, java.lang.object expected, java.lang.object actual). if compare primitive types in case of assert failure visible in test report values different, e.g. in case of 2 integers comparison. when compare 2 complex objects output of test can quite cluttered. if have override tostring() method list fields values output long. imagine having class:

public class invoice {      private localdate invoicedate;     private string invoicenumber;     private invoicetype invoicetype;     private invoicestatus invoicestatus;     private string mediaplanner;     private string yourreference;     private string responsibleperson;     private brand advertiser;     private mediaagency mediaagency;     private set<invoicerow> invoicerows;     ..... 

the invoicerow quite complex object lot of own fields. if put these fields tostring() implementation , assert fails junit output quite long message not easy read eyes in order see in 1 object invoice type, example, incorrect.

is there tools/approaches improve in way test report show rather clear , concise output in case when comparison fails? maybe should use other test frameworks has more tooling/features?

implement own assert method.

import static org.junit.assert.assertequals; ... public static void assertequals(invoice expected, invoice actual) {     assertequals("invoicedate", expected.invoicedate, actual.invoicedate);     assertequals("netprice", expected.netprice, actual.netprice);     assertequals("invoicerows", expected.invoicerows, actual.invoicerows);     // , on... } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -