1 使用testng框架进行web的单元测试,不用每次都启动tomcat
@ContextConfiguration(locations={"application-context.xml"}) @TransactionConfiguration(defaultRollback = true) public class TestSafety extends AbstractTestNGSpringContextTests { @Autowired SafetyStockJob safetyStockJob; @Test public void test1(){ List<String> list=safetyStockJob.getFH_date(); System.out.println(1234); System.out.println(list.toString()); System.out.println(list.size()); } }
2 使用spring提供的单元测试插件
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:applicationContext.xml" }) public class SSHTest { @Resource private SysUserDao sysUserDao; @Resource private SysUserService sysUserService; @Before public void setUp() throws Exception { } @Test public final void testSave() { // System.out.println("sysUserService:::" + sysUserService); SysUser sysUser = sysUserService.getByProerties("userName", "admin"); } }
时间: 2024-12-28 11:53:05