UnitilsJUnit4Test功能介绍

UnitilsJUnit4BaseTest.java文件:

/**
 * 
 */
package unitilsjunit4test;

import org.junit.runner.RunWith;
import org.unitils.UnitilsJUnit4TestClassRunner;
import org.unitils.spring.annotation.SpringApplicationContext;

/**
 * @author Administrator
 *
 */
@SpringApplicationContext({ "classpath*:core/persistence/beans.xml" })
@RunWith(UnitilsJUnit4TestClassRunner.class)//或者BaseTest继承extends UnitilsJUnit4
public class UnitilsJUnit4BaseTest {

}

UnitilsJUnit4Test.java文件:

/**
 * Copyright (C) 2006-2012 Tuniu All rights reserved
 * Author:tianzhipeng
 * Date:2012-7-9
 * Description: 
 */

package unitilsjunit4test;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import junit.framework.Assert;

import org.junit.Test;
import org.unitils.spring.annotation.SpringBeanByType;

import core.domain.User;
import core.service.IUserService;

/**
 * Description : Menpiao unit test
 */

//@SpringApplicationContext({ "classpath*:core/persistence/beans.xml" })
//@RunWith(UnitilsJUnit4TestClassRunner.class)
public class UnitilsJUnit4Test extends UnitilsJUnit4BaseTest{
    @SpringBeanByType
    private IUserService userService;

    @Test
    public void testSaveMenpiao() {
        Map<String, Object> data = new HashMap<String, Object>();
        User user = userService.getUserByName("tom");
        System.out.println(user.getName());
        Assert.assertEquals(user.getName(), "tom");
    }

    @Test
    public void testGetRequest() {
        HttpServletRequest request = null;
    }
}

需要jar包:junit-4.10.jar,unitils-2.4.jar

 

 

posted @ 2012-09-02 09:29  唾手可得的树  阅读(499)  评论(0编辑  收藏  举报