Spring:测试Service类中方法

Maven坐标



   junit
   junit
   4.11



   org.springframework
   spring-test
   4.2.0

业务代码

Spring配置类




    
    

    
    


Service接口

package com.fly.cloudpay.service.user;

import com.fly.cloudpay.dao.entity.PayUserDO;

import java.util.Map;

/**
 * @Title: 缴费用户信息--Service
 * @ClassName: com.fly.cloudpay.service.user.PayUserService.java
 * @Description:
 *
 * @Copyright 2016-2018  - Powered By 研发中心
 * @author: 王延飞
 * @date:  2018-03-02 14:24
 * @version V1.0
 */
public interface PayUserService {

  

    /**
     * @Title: 新增用户信息
     * @methodName:  add
     * @param payUserDO
     * @return void
     * @Description:
     *
     * @author: FLY
     * @date:  2018-03-02 15:15
     */
    void add(PayUserDO payUserDO);

}

Service实现类

package com.newcapec.fly.service.user.impl;

import com.newcapec.fly.constant.ControllerConstant;
import com.newcapec.fly.dao.PayUserDao;
import com.newcapec.fly.dao.entity.PayUserDO;
import com.newcapec.fly.service.user.PayUserService;
import com.newcapec.util.map.MapBeanTransUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.Map;

/**
 * @version V1.0
 * @Title: 缴费用户信息--Service实现层
 * @ClassName: com.newcapec.fly.service.user.impl.PayUserServiceImpl.java
 * @Description:
 * @Copyright 2016-2018  - Powered By 研发中心
 * @author: FLY
 * @date: 2018-03-02 14:24
 */
@Service
public class PayUserServiceImpl implements PayUserService {

    private static final Logger log = LoggerFactory.getLogger(PayUserServiceImpl.class);

    @Autowired
    private PayUserDao payUserDao;



    /**
     * @param payUserDO
     * @return void
     * @Title: 新增缴费用户信息
     * @methodName: add
     * @Description:
     * @author: FLY
     * @date: 2018-03-02 15:15
     */
    @Override
    public void add(PayUserDO payUserDO) {

        log.info("【新增缴费用户信息】,接收参数:{}", payUserDO);
        payUserDao.save(payUserDO);
    }

    

}

Spring测试类

package service;

import com.fly.cloudpay.dao.PayUserDao;
import com.fly.cloudpay.dao.entity.PayUserDO;
import com.fly.cloudpay.service.user.PayUserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @Title:
 * @ClassName: service.ServiceTest.java
 * @Description:
 *
 * @Copyright 2016-2018  - Powered By 研发中心
 * @author: FLY
 * @date:  2018-03-01 11:35
 * @version V1.0
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/applicationContext-dao.xml",
        "classpath:spring/applicationContext-spring.xml"})
public class ServiceTest {

    @Autowired
    PayUserService payUserService;


    @Autowired
    private PayUserDao payUserDao;

    @Test
    public void payUserAddTest(){

        PayUserDO payUserDO = new PayUserDO();
        payUserDO.setPayUserIdNum("123456");
        payUserDO.setPayUserName("FLY");
        payUserDO.setBindTime(new java.util.Date());
        payUserService.add(payUserDO);
    }

   
}

 

你可能感兴趣的:(Spring)