原创

spring mvc 配置 JUnit4 进行测试 service 和 jdbc查询

@RunWith(SpringJUnit4ClassRunner.class)
@PropertySource(value={"classpath*:config/jdbc.properties","classpath*:config/log4j.properties",""})
@ContextConfiguration(locations={"classpath*:config/mybatis-config.xml","classpath*:config/spring-mybatis.xml",
"classpath*:config/springmvc-servlet.xml","classpath*:config/spring.xml"})
public class BaseJunitTest {

}

上面为编写的测试父类

测试类只要继承上面的配置类

public class SysTaskDemo extends BaseJunitTest {
@Autowired
SysTaskService sysTaskService;
@Autowired
JobTask jobTask;

@Test
public void jobTaskTest(){
SysTask s = sysTaskService.findById(1);
System.out.println("====================="+s.getTaskName());
}

}
正文到此结束
Loading...