Transaction roll back is not working in test case in @Nested class of JUnit5

后端 未结 2 758
南旧
南旧 2020-12-11 05:35

I use spring-boot, JUnit5, Mybatis.

@SpringJUnitJupiterConfig(classes = {RepositoryTestConfig.class})
@MapperScan
@Rollback
@Transactional
public class TestC         


        
相关标签:
2条回答
  • 2020-12-11 06:00

    I solved it in the following way..

    @SpringJUnitJupiterConfig(classes = {RepositoryTestConfig.class})
    @MapperScan
    @Rollback
    @Transactional
    public class TestClass {
        @Autowired
        private TestMapper testMapper;
    
        @BeforeEach
        void init() {
            User user = new User();
            testMapper.insert(user);    
        }
    
        @Nested
        @SpringJUnitJupiterConfig(classes = {RepositoryTestConfig.class})
        @MapperScan
        @Rollback
        @Transactional
        class WhenExistData {
            @Test
            public void test2() {
            }   
        }
    }
    
    0 讨论(0)
  • 2020-12-11 06:06

    This is to be expected: the Spring TestContext Framework has never supported "inheritance" for nested test classes.

    Thus your "work around" is actually the correct way to achieve your goal at this point in time.

    Note, however, that I may add support for "pseudo-inheritance" for nested test classes in conjunction with SPR-15366.

    Regards,

    Sam (author of the Spring TestContext Framework)

    0 讨论(0)
提交回复
热议问题