Spring——集成Junit


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SpringCofiguration.class})
// @ContextConfiguration("classpath:applicationContext.xml")
// 需要的对象直接依赖注入。即可调用对象。 (对象需要存在spring容器中)
public class SpringJunitTest {

@Autowired //依赖注入
private UserService userService;

@Autowired //依赖注入
private ComboPooledDataSource comboPooledDataSource;

@Test
public void test1(){
userService.save();
}

@Test
public void test2() throws SQLException {
Connection con = comboPooledDataSource.getConnection();
System.out.println(con);
}
}