Integration Tests - Student-Management-System/Sparkyservice-Project GitHub Wiki
We use maven default naming convention. Each test with IT
suffix is treated as integration test by maven.
Class decorator
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = {"classpath:test-routing.properties"})
@AutoConfigureMockMvc
To write an integration test use @IntegrationTest
(net.ssehub.sparkyservice.api.testconf.IntegrationTest) as method decorator.
- To use a real database via docker, the class must extends
AbstractContainerTestDatabase
. Apostgresql
container is started before each test. - In order to use this feature Docker must be installed.
Example command for ubuntu:
apt install docker
- The used property file in the test class must include
spring.jpa.hibernate.ddl-auto = create
. Recommended is a full configured block:
# Spring - Database
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=<automatic>
spring.datasource.username=<automatic>
spring.datasource.password=<automatic>
spring.jpa.show-sql = false
spring.jpa.hibernate.ddl-auto = create
During integration tests, the following ports are used:
- 1080 on 127.0.0.1 for a mocked http server