Here is an example of (overly) simplified code to describe the unit testing method.
CompanyDataSet.xml
<dataset> <company company_key="100" company_name="OldName" /> </dataset>
CompanyDaoTest.java
@Test public void testUpdateCompany() { CompanyDao companyDao = new CompanyDao(); IDatabaseConnection dbConn = createConnection(); IDataSet dataSet = createDataSet("CompanyDataSet.xml"); DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet); companyDao.updateCompany(100, "NewName");
I came up with two ways to approve company data.
Create another xml dataset as the expected dataset.
different xml
<dataset> <company company_key="100" company_name="NewName" /> </dataset>
Approve Part in Java
IDataSet actual = dbConn.createDataSet(new String[]{"company"}); IDataSet expected = createDataSet("CompanyDataSet_expected.xml"); Assertion.assertEquals(expected, actual);
Just upload the company object through the DAO and compare the properties.
you should get this idea.
My problem
The first method is quite easy to write, but I need to create a different XML file for each other update method. The dose does not seem to be a good idea for creating so much XML data files.
The second method is simple, however, when there are various update methods, the test class is populated with methods that claim different properties with different values. And Lot's tests will break if something is wrong with the boot method.
Is there a good way to validate the data? Is it possible to avoid the problem that I just described (or is it really not important)?
UPDATE
Since no one answers the question, I decide to accept my answer.