基于spring3 单元测试例子
package com.smartlife.test;import org.junit.Before;import org.junit.Test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.annotation.Rollback;import org.springframework.test.context.ContextConfiguration;import org.springside.modules.test.spring.SpringTxTestCase;import com.smartlife.service.BrandService;@ContextConfiguration(locations = { "/applicationContext.xml" })public class TestSpringjunit extends SpringTxTestCase { @Autowired private BrandService brandService; @Beforepublic void reloadSampleData() throws Exception {//Fixtures.reloadAllTable(dataSource, "/data/sample-data.xml");}@Test//如果你需要真正插入数据库,将Rollback设为false@Rollback(false) public void crudEntity() {System.out.println(brandService);}}