Here are some (overly) simplified code example to describe my 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");
// What is a good way to assert updated company data ?
}
I came up with two ways to assert company data.
Create another dataset xml as expected dataset.
another XML
<dataset>
<company company_key="100" company_name="NewName" />
</dataset>
Assert part in Java
IDataSet actual = dbConn.createDataSet(new String[]{"company"});
IDataSet expected = createDataSet("CompanyDataSet_expected.xml");
Assertion.assertEquals(expected, actual);
Just load the company object through DAO, and compare the properties.
you should get the idea.
My Problem
The first way is pretty easy to write, but I have to create another XML file for each different update method. It dose not sounds like a good idea to create so many data set XML files.
The second way is straightforward, however, when there are different update methods, the test class will filled with methods that assert different properties with different value. And Lots tests will broke if there are something wrong with load method.
Is there a good way to assert the data ? is it possible to avoid the problem I just described (or it dosen't really matter) ?
UPDATE
Since there is no one answer the question, I decide to accept my answer.