class UnitTestBase 这个类就不能说一下吗? 完整的代码在哪里
package com.imooc.test.base;
import org.junit.After;
import org.junit.Before;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class UnitTestBase {
String springXmlPath;
ClassPathXmlApplicationContext context;
public UnitTestBase() {}
public UnitTestBase(String springXmlPath){
this.springXmlPath = springXmlPath;
}
@Before
public void before(){
if("" == springXmlPath){
springXmlPath = "classpath*:spring-*.xml";
}
try{
context = new ClassPathXmlApplicationContext(springXmlPath.split("[,\\s]+"));
context.start();
}catch(Exception e){
e.printStackTrace();
}
}
@After
public void after(){
context.destroy();
}
public <T extends Object > T getBean(String beanId){
try{
return (T) context.getBean(beanId);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}