public class testService { public static EnterpriseinfoServiceImpl service; @BeforeClass public static void setUpBeforeClass() throws Exception { System.out.println("加载配置文件……"); ApplicationContext context = new FileSystemXmlApplicationContext(new String[]{"src/applicationContext.xml"}); System.out.println("加载配置文件成功"); service = (EnterpriseinfoServiceImpl) context.getBean("enterpriseinfoService"); //enterpriseinfoService为applicationContext.xml配置文件中Service类对象id值 } @Test public void testSave() { try { Enterpriseinfo info = new Enterpriseinfo(); info.setEnglishabbreviation("Myenglishname"); info.setEnglishfullname("myenglishfullname"); info.setEnterpriseabbreviation("enterpriseabbreviation"); info.setEnterprisefullname("enterprisefullname"); info.setStockcode(12434); info.setId(3); service.save(info); } catch (Exception e) { e.printStackTrace(); } } }
使用JUnit4对SSH2框架Service/Dao层进行单元测试
原文:http://blog.csdn.net/redeagle_gbf/article/details/18738387