`
菜鸟求带_1
  • 浏览: 6782 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Spring 中的单元测试

阅读更多
第一种方式:
//spring整合junit4

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;

/**
 * Created by staunch on 2016-07-12.
 * version:v1.0
 * instruction:初始版本
 */
@RunWith(SpringJUnit4ClassRunner.class) // 整合
@ContextConfiguration(locations="classpath:config/applicationContext.xml") // 加载配置
public class AdvisorServiceTest {

    @Autowired
    private //注入测试依赖

    @Test
    public void testCheckStudentInfo() throws Exception {
        //测试代码
    }
}


第二种方式:
//Spring+testNG

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by staunch on 2016-06-29.
 * version:v1.0
 * instruction:初始版本
 */
@ContextConfiguration(locations = {"/config/applicationContext.xml"})
public class AdvisorMapperTest extends AbstractTestNGSpringContextTests{
    @Autowired
    //注入的测试依赖

    @Test
    public void testBatchInsertDiscussion() throws Exception {
            //测试代码
        }
        );
    }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics