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

  • 相关阅读:
    ov5640调试过程
    关于OnPaint函数的工作原理(很详细,很实用) [转载]
    机器视觉网络资源
    (转)signaltap II数据用于仿真
    DataSocket简介
    datasocket使用网络传输图像
    共享变量/全局变量/datasocket
    [转载] 任意频率分频原理
    [转]影响FPGA设计中时钟因素的探讨
    生产者和消费者
  • 原文地址:https://www.cnblogs.com/ff111/p/13178104.html
Copyright © 2020-2023  润新知