Simple and easy to understand the test class in springMVC

package test;

import entity.Product;
import mapper.ProductMapper;
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;

/**
 * zt
 * 2020/10/12
 * 21:38
 */
//@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
@RunWith(SpringJUnit4ClassRunner.class)
//用于测试加载spring环境常与@RunWith联用
@ContextConfiguration(locations = "classpath:application.xml")
public class TestMapper {
    @Autowired
    private ProductMapper mapper;
    @Test
    public void test1(){
        Product p = new Product();
        p.setTid(1);
        p.setPname("aaa");
        mapper.add(p);
    }

    @Test
    public void test2(){
        mapper.delete(2);
    }

}

Guess you like

Origin blog.csdn.net/qq_39773004/article/details/109046787