在@Transactional测试中回滚@Sql(executionPhase = BEFORE_TEST_METHOD)所做的更改

时间:2018-02-20 07:46:42

标签: spring spring-test transactional

我有测试:

@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
ClassServiceTest

测试方法:

@Sql(executionPhase = BEFORE_TEST_METHOD, scripts ="test.sql")
public void methodTest() {
}

据我所知,带有SpringJUnit4ClassRunner的@Transactional会使所有测试sql / db更改为回滚。在方法之前执行的@Sql脚本是否会被回滚到?

1 个答案:

答案 0 :(得分:0)

您可以使用SqlGroup批注手动控制数据库更改:

library(shiny)
library(miniUI)

myGadgetFunc <- function() {

  ui <- miniPage(
    gadgetTitleBar("My Gadget"),
    miniContentPanel(
      fileInput('file1', 'Choose a file to upload',
                accept = c(
                  'text/csv',
                  'text/comma-separated-values',
                  'text/tab-separated-values',
                  'text/plain',
                  '.csv',
                  '.tsv'
                )
      )
    ),
    DT::dataTableOutput("tbl")


  )

  server <- function(input, output, session) {
    rv <- reactiveValues(data = NULL)

    observe( {
      req(input$file1)

      inFile <- input$file1
      data2 <- read.csv(inFile$datapath, stringsAsFactors=FALSE)
      save(data2, file = "dataread.RData")

      rv$data <- data2
    })

    output$tbl <- DT::renderDataTable({
      req(rv$data)
      rv$data
    })

    # When the Done button is clicked, return a value
    observeEvent(input$done, {
      returnValue <- rv$data
      stopApp(returnValue)
    })
  }

  runGadget(ui, server)
}