码迷,mamicode.com
首页 > 编程语言 > 详细

Java 8.Spring--整合Junit测试

时间:2020-01-05 20:28:39      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:text   ext   java 8   ring   package   pack   img   com   导入   

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);
	}
	

}

 

  

Java 8.Spring--整合Junit测试

标签:text   ext   java 8   ring   package   pack   img   com   导入   

原文地址:https://www.cnblogs.com/yuzhenfu/p/12153318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!