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);
}
}