Hello guys! What is the option of rollback transac...
# kotest
u
Hello guys! What is the option of rollback transaction in @SpringBootTest on DescribeSpec test class? My dev environment consists of kotlin, spring boot and spring data jpa. So by afterContainer lifecycle function, i manually call jpaRepository.deleteAll() method to to keep testdb clear. But the number of test classes grows up, calling deleteAll() method is very boring thing and could forget to call it. Code snippet is down…
Copy code
[오전 9:16] @AutoConfigureMockMvc
@SpringBootTest
class MyTest(
    private val orderRepository: OrderRepository,
    private val itemRepository: OrderItemRepository,
    private val mockMvc: MockMvc,
    private val objectMapper: ObjectMapper,
) : DescribeSpec({

    describe("create orderLine api integration test") {

        context("when api called successfully") {

            // prepare dataset
            val order = createOrder()
            val item = createItem()
            order.add(item)
            orderRepository.save(order)

            // when calling requestApi function,
            val requestApi = {
                <http://mockMvc.post|mockMvc.post>("/api/orders") {
                    contentType = MediaType.APPLICATION_JSON
                    content = objectMapper.writeValueAsString(order)
                }
            }

            it("returns status code 200") {
                requestApi().andExpect { status { isOk() } }
            }
        }
    }

    // clear dataset
    afterContainer {
        itemRepository.deleteAll()
        orderRepository.deleteAll()
    }
})
Im using DescribeSpec and usually i call IO operation methods on context container. And the test is finished, i want to clearr all changed data that prepared dataset order and orderItem and some other created or updated by calling requestApi. My idea is using PlatformTransactionManager and start or commit transaction manually… (편집됨)
e
AFAIK rollback should be enabled by default? If it's not, try setting
@Transactional
on your test class?