码迷,mamicode.com
首页 > 其他好文 > 详细

Sping TestNG 启用事物@Transactional

时间:2020-06-22 19:17:35      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:ack   false   extc   文件加载   test   bst   cti   div   create   

import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.BeforeClass;

@ContextConfiguration(locations = {"classpath*:conf/spring/spring-context-test.xml"})//配置文件加载
public abstract class BaseTestNG extends AbstractTransactionalTestNGSpringContextTests {

    public static final Logger LOGGER = LoggerFactory.getLogger(BaseTestNG.class);

    public abstract void initMock();
    @BeforeClass(alwaysRun = true)
    public void init() {
        MockitoAnnotations.initMocks(this);
        this.initMock();
    }
}

 

 

 

记得继承:AbstractTransactionalTestNGSpringContextTests

public class CategoryServiceImplTest extends BaseTestNG {

    @Autowired
    CategoryService categoryService;

    @Test(priority = 100)
    @Rollback(value = true)
    public void testCreateAdminPlatformCategory() {
        CreateAdminPlatformCategoryInDTO createAdminPlatformCategoryInDTO = new CreateAdminPlatformCategoryInDTO();
        createAdminPlatformCategoryInDTO.setCategoryName("单元测试001");
        createAdminPlatformCategoryInDTO.setOperatorUser("17093352");
        LOGGER.info("输出:{}", categoryService.createAdminPlatformCategory(createAdminPlatformCategoryInDTO));
    }
}
@Rollback(value = true) value=false可以阻止回滚

 

Sping TestNG 启用事物@Transactional

标签:ack   false   extc   文件加载   test   bst   cti   div   create   

原文地址:https://www.cnblogs.com/ff111/p/13178104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!