zoukankan      html  css  js  c++  java
  • 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);
    	}
    	
    
    }
    

      

  • 相关阅读:
    &&和||解析
    SQL-union union all
    sql杂记
    JAVA杂记
    sql之left join、right join、inner join的区别
    蓝鲸邮箱配置
    快速部署社区版(详解)
    蓝鲸平台安装环境准备
    蓝鲸脚本集合
    zabbix3.4 install
  • 原文地址:https://www.cnblogs.com/yuzhenfu/p/12153318.html
Copyright © 2011-2022 走看看