Integration Tests - Student-Management-System/Sparkyservice-Project GitHub Wiki

Class Setup

Maven

We use maven default naming convention. Each test with IT suffix is treated as integration test by maven.

SpringBoot init

Class decorator

@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = {"classpath:test-routing.properties"})
@AutoConfigureMockMvc

Define integration test with Junit

To write an integration test use @IntegrationTest (net.ssehub.sparkyservice.api.testconf.IntegrationTest) as method decorator.

Database

  1. To use a real database via docker, the class must extends AbstractContainerTestDatabase. A postgresql container is started before each test.
  2. In order to use this feature Docker must be installed. Example command for ubuntu: apt install docker
  3. 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

Used Ports

During integration tests, the following ports are used:

  • 1080 on 127.0.0.1 for a mocked http server
⚠️ **GitHub.com Fallback** ⚠️