zoukankan      html  css  js  c++  java
  • Sping TestNG 启用事物@Transactional

    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可以阻止回滚

  • 相关阅读:
    Java 8 Stream流编程学习
    AMD R5 2400G插帧教程
    GCC编译Win图形程序不显示控制台方法
    Linux程序守护脚本
    远程桌面软件RDCMan汉化版
    Java基础知识点
    Java的String类常用方法
    Apache Commons 相关工具类使用
    基于OpenCV的双目视觉匹配测距系统
    异想家Ubuntu安装的软件
  • 原文地址:https://www.cnblogs.com/ff111/p/13178104.html
Copyright © 2011-2022 走看看