Spring3.0的Junit测试


关于Spring3.0Junit的测试,研究了半天,发现elcpase内置的junit为4.5的版本,而Spring3.0的Junit的测试需要4.9以上的版本,代码如下:


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;


import com.gcca.dao.GridDao;
import com.gcca.data.TblGrid;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:WebContent/WEB-INF/spring/app-config.xml"})
@TransactionConfiguration(defaultRollback = false)
public class TestTblGrid {


@Autowired
private GridDao gridDao;

@Test
public void TestSave(){
TblGrid grid = new TblGrid();
grid.setGid(1);
grid.setgName("BaseDevice");
grid.setGsts("0");
gridDao.SaveGrid(grid);
System.out.println("save finish!!");
}
}

你可能感兴趣的:(Junit,Spring)