• Create – database instance is not necessary
  • Prepare – clean tables, load data to datasource
  • Assert – verify your datasource contains expected data
@Test   
public void testGetCustomerFromDao()
{
	//business dao object
	final CustomerDao customerDao = new CustomerDao();

	// initialize DbAssert
	final DbAssert dbAssert = DbAssert.init("org/testfw/TestSource.xml");

	// create a "fake" datasource. Stanalone instance of HSQLDB will be created (no database required). 
	final DbSource myTestSource = dbAssert.fake_source("testSrc","org/testfw/testSourceSchema.sql", getClass());

	// clean "customers" table
	myTestSource.clean_table("customers");
	
	//load data from customers.yml file
	final Fixture customerFixtures = myTestSource.fixture("customers");
	final Fixture customer_one  = (Fixture) customerFixtures.get("customer_one");

	//make an assertion    
	assertEquals(customer_one.get("name"), customerDao.findById(customer_one.get("id")));
}    
Advertisements