spring4.x整合junit

1.所需jar包


  junit
  junit
  4.11

  org.springframework
  spring-test
  4.2.1.RELEASE

2.以下为目录结构,weorderTest.java文件就是我们用于写junit单元测试的文件

spring4.x整合junit_第1张图片

3.weorderTest.java文件内容:

package wxorderTest;

import com.lanswon.dao.t_posstaffbookingMapper;
import com.lanswon.dto.BaseDto;
import com.lanswon.dto.Dto;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext.xml")
//多文件可以@ContextConfiguration(locations = { "classpath:spring1.xml", "classpath:spring2.xml"
public class wxorderTest extends AbstractJUnit4SpringContextTests {

    @Resource
    private t_posstaffbookingMapper wxMapper;
    @Test
    public void saveTest() {
        Dto dto = new BaseDto();
        List list = wxMapper.queryRestaurant(dto);
        System.out.println(list);
    }
}

你可能感兴趣的:(javaWEB开发)