• j2ee web项目 ssh 中使用junit测试


    需要导入两个包:org.springframework.test-3.0.3.RELEASE.jar和junit-4.8.1.jar ,

    测试类需要继承:AbstractJUnit4SpringContextTests,同时测试方法上加上@Test

    代码实例:

    package com.ss.test;
    
    import java.util.List;
    
    import javax.annotation.Resource;
    
    import org.junit.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
    
    import com.ss.bean.Product;
    import com.ss.service.query.QueryService;
    
    /**
     * junit 单元测试
     * @author wy
     *
     */
    @ContextConfiguration(locations = { "/bean.xml" })//指定spring配置文件位置
    public class JunitTest extends AbstractJUnit4SpringContextTests {
    
    	@Resource
    	private QueryService queryService;  //注入bean
    
    	@Test
    	public void test1() {
    		String keyWord = "空"
                    //下面的service就是访问数据库,然后返回查询结果
    		List<Product> products = queryService.products(keyWord);
    		for (Product product : products) {
    			System.out.println("name:" + product.getName());
    		}
    	}
    }
    


  • 相关阅读:
    Title
    Title
    Title
    Title
    Python生成随机验证码
    Time模块和datetime模块
    For循环的实质
    Python函数
    集合set
    字符串内置方法的使用
  • 原文地址:https://www.cnblogs.com/wyang0126/p/5039932.html
Copyright © 2020-2023  润新知