Spring单元测试
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)//使用junit4进行测试
@ContextConfiguration({"/applicationContext.xml"})//加载配置文件
public class ServiceTest {
@Autowired //自动注入,测试的服务,默认按名称
TestService testService;
@Test //标明是测试方法
public void test(){
testService.createTest(command);
}
}