Spring Junit测试模板

来源:互联网 发布:linux怎么关闭tomcat 编辑:程序博客网 时间:2024/06/06 18:07
import javax.annotation.Resource;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.annotation.Rollback;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import org.springframework.test.context.transaction.TransactionConfiguration;import org.springframework.transaction.annotation.Transactional;import com.shixun.domain.Person;@RunWith(SpringJUnit4ClassRunner.class)  @TransactionConfiguration(transactionManager = "txManager")  @ContextConfiguration(locations = {"classpath*:/applicationContext.xml", "classpath*:/spring-servlet.xml"}) @Transactional  public class PersonControllerTest {    @Resource    private PersonController personController;    @Test       @Rollback(false)    public void test_savePerson(){        Person p = new Person();        p.setName("zhangsan");        personController.savePerson(p);    }}
0 0