JUnit单元测试中获取Spring中的bean测试类的编写

1、编写测试类

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;

import com.hp.approval.single.impl.SingleInterfaceManager;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:/spring/context-*.xml"})//从web.xml中获取contextConfigLocation路径
public class TestInterface {
	
	@Autowired
	
	private SingleInterfaceManager manager;
	
	@Test
	public void TestApproval(){
		manager.checkSingleApproval();
	}

}

2.web.xml格式

JUnit单元测试中获取Spring中的bean测试类的编写_第1张图片

你可能感兴趣的:(Spring)