Merge pull request #15553 from Michaelin007/integrationtest

https://jira.baeldung.com/browse/BAEL-7375
This commit is contained in:
Maiklins 2024-01-12 23:26:06 +01:00 committed by GitHub
commit e2e9b10e68
3 changed files with 8 additions and 6 deletions

View File

@ -74,6 +74,7 @@
<validation-api.version>2.0.1.Final</validation-api.version> <validation-api.version>2.0.1.Final</validation-api.version>
<mysql-connector-java.version>8.2.0</mysql-connector-java.version> <mysql-connector-java.version>8.2.0</mysql-connector-java.version>
<start-class>com.baeldung.boot.Application</start-class> <start-class>com.baeldung.boot.Application</start-class>
<spring-boot.version>3.2.0</spring-boot.version>
</properties> </properties>
</project> </project>

View File

@ -1,6 +1,7 @@
package com.baeldung.springbootinitialload.tests; package com.baeldung.springbootinitialload.tests;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.*;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -16,7 +17,8 @@ import com.baeldung.boot.repository.EmployeeRepository;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
@Sql({"/employees_schema.sql", "/import_employees.sql"}) @Sql(scripts = {"/employees_schema.sql", "/import_employees.sql"}, executionPhase = BEFORE_TEST_CLASS)
@Sql(scripts = {"/delete_employees_data.sql"}, executionPhase = AFTER_TEST_CLASS)
public class SpringBootInitialLoadIntegrationTest { public class SpringBootInitialLoadIntegrationTest {
@Autowired @Autowired
@ -24,14 +26,12 @@ public class SpringBootInitialLoadIntegrationTest {
@Test @Test
public void testLoadDataForTestClass() { public void testLoadDataForTestClass() {
assertEquals(3, employeeRepository.findAll() assertEquals(3, employeeRepository.findAll().size());
.size());
} }
@Test @Test
@Sql(scripts = {"/import_senior_employees.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = TransactionMode.ISOLATED)) @Sql(scripts = {"/import_senior_employees.sql"}, executionPhase = BEFORE_TEST_METHOD ,config = @SqlConfig(encoding = "utf-8", transactionMode = TransactionMode.ISOLATED))
public void testLoadDataForTestCase() { public void testLoadDataForTestCase() {
assertEquals(5, employeeRepository.findAll() assertEquals(5, employeeRepository.findAll().size());
.size());
} }
} }

View File

@ -0,0 +1 @@
DROP TABLE EMPLOYEES;