[英]Test data of one test case getting reflected in another test case
I am trying to use @sql and @sqlgroup on my unit test. 我试图在单元测试中使用@sql和@sqlgroup。 I have 2 test cases namely testA and testB.
我有2个测试用例,分别是testA和testB。 The sqlgroup for testA is
testA的sqlgroup是
@SqlGroup({
@Sql(value = "classpath:test/scripts/testA-service/before-test.sql",
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD),
@Sql(value = "classpath:test/scripts/testA-service/before-testA.sql",
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD),
@Sql(value = "classpath:test/scripts/testA-service/after-test.sql",
executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
})
The sqlgroup for testB is testB的sqlgroup是
@SqlGroup({
@Sql(value = "classpath:test/scripts/testB-service/before-test.sql",
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD),
@Sql(value = "classpath:test/scripts/testB-service/before-testB.sql",
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD),
@Sql(value = "classpath:test/scripts/testB-service/after-testB.sql",
executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD),
@Sql(value = "classpath:test/scripts/testB-service/after-testB.sql",
executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
})
In before-testA.sql I insert in a table named TABLE1 some random values. 在before-testA.sql中,我在名为TABLE1的表中插入了一些随机值。 In the after-test.sql of testA-service, I truncate TABLE1.
在testA-service的after-test.sql中,我截断了TABLE1。
In before-test.sql of testB-service, I drop TABLE1 if it exists and then create it again. 在testB-service的before-test.sql中,如果存在TABLE1,则将其删除,然后再次创建它。 I insert in TABLE1 some random values again.
我再次在表1中插入一些随机值。 In the after-test.sql of testB-service, I truncate TABLE1.
在testB-service的after-test.sql中,我截断了TABLE1。
While running the test case testB, the values in TABLE1 being used are not of the one inserted second time. 在运行测试用例testB时,正在使用的TABLE1中的值不是第二次插入的值。 Instead it uses the value inserted first time.
而是使用第一次插入的值。
I am using HSQLdb. 我正在使用HSQLdb。 This issue is not arising locally but in the prod/dev server.
此问题不是在本地出现,而是在prod / dev服务器中出现。
If this is an in-process file: database and the two tests are two separate processes, make sure you execute "SHUTDOWN" at the end of the AFTER_TEST of first test. 如果这是一个进程中文件:数据库和两个测试是两个单独的进程,请确保在第一个测试的AFTER_TEST的末尾执行“ SHUTDOWN”。
With a HSQLDB server hsql: connection, or when the two tests are in the same Java process and your database is a mem: the "SHUTDOWN" should NOT be executed. 使用HSQLDB服务器hsql:连接,或者当两个测试在同一Java进程中并且您的数据库是内存时:不应执行“ SHUTDOWN”。 In the second dase it would lose everyting done by the first test.
在第二种情况下,它将失去第一种测试所完成的一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.