`

在Spring框架下 使用junit进行单元测试

    博客分类:
  • Java
阅读更多

package com.yourPackage.test;

import static org.junit.Assert.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.yourPackage.service.ServiceA;
import com.yourPackage.service.ServiceB;

public class MyTest {
    private PnlCachingService caching;
    private PnlHistoricalService hist;
    @Before
    public void setUp() throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"file:WebContent/WEB-INF/applicationContext.xml"});
        BeanFactory factory = (BeanFactory) context;
        serviceA = (ServiceA) factory.getBean("ServiceA");
        serviceB = (ServiceB) factory.getBean("ServiceB");
    }

    @Test
    public void testYourService(){
       
        try{
            List rtnA = serviceA.functionA();
            List rtnB = serviceB.functionB();
            Assert.assertEquals(rtnA, rtnB);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics