Java 8.Spring--整合Junit测试
1.导包
导入spring-test包
2.在Person中添加注解
import com.Spring.pojo.Person; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml")
3.创建测试类
package com.spring.pojo; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.Spring.pojo.Person; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml") public class RunWithTest { @Resource(name="person") private Person p; @Test @SuppressWarnings("resource") public void testProperty() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-injection.xml"); Person person1=(Person) context.getBean("person1"); System.out.println(person1); } }
相关推荐
shirleypaddy 2020-10-19
qingmumu 2020-10-19
lustdevil 2020-10-18
ganlulululu 2020-10-12
lustdevil 2020-08-03
lustdevil 2020-07-18
lustdevil 2020-06-25
lustdevil 2020-06-21
zhengzf0 2020-06-21
宿命java 2020-06-15
JackYin 2020-06-14
dongxurr 2020-06-07
snowphy 2020-06-06
zhengzf0 2020-05-28
81901836 2020-05-26
Julywhj 2020-05-26