老師這個有點坑啊?。? import org.junit.Test; 這里導入全部隱藏看不到導入什么??
public class TestOneInterface extends UnitTestBase{} 這里的UnitTestBase 是老師自己定義的類吧 也沒提供 根本找不到?。?!
老師這個有點坑啊?。? import org.junit.Test; 這里導入全部隱藏看不到導入什么??
public class TestOneInterface extends UnitTestBase{} 這里的UnitTestBase 是老師自己定義的類吧 也沒提供 根本找不到?。?!
2014-09-23
舉報
2015-03-25
package com.imooc.test.base;
import org.junit.After;
import org.junit.Before;
import org.springframework.beans.BeansException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StringUtils;
public class UnitTestBase {
private ClassPathXmlApplicationContext context;
private String springXmlpath;
public UnitTestBase() {}
public UnitTestBase(String springXmlpath) {
this.springXmlpath = springXmlpath;
}
@Before
public void before() {
if (StringUtils.isEmpty(springXmlpath)) {
springXmlpath = "classpath*:spring-*.xml";
}
try {
context = new ClassPathXmlApplicationContext(springXmlpath.split("[,\\s]+"));
context.start();
} catch (BeansException e) {
e.printStackTrace();
}
}
@After
public void after() {
context.destroy();
}
@SuppressWarnings("unchecked")
protected <T extends Object> T getBean(String beanId) {
try {
return (T)context.getBean(beanId);
} catch (BeansException e) {
e.printStackTrace();
return null;
}
}
protected <T extends Object> T getBean(Class<T> clazz) {
try {
return context.getBean(clazz);
} catch (BeansException e) {
e.printStackTrace();
return null;
}
}
}
2014-09-23
?UnitTestBase是自定義的類,import內容如下:
import?org.junit.Test;
import?org.junit.runner.RunWith;
import?org.junit.runners.BlockJUnit4ClassRunner;
import?com.imooc.ioc.interfaces.OneInterface;
import?com.imooc.test.base.UnitTestBase;