Main language: Groovy. Project functional tests use Spock as a main testing framework. Also used Docker for running PBS and other services. Testcontainers is used as provider of lightweight, throwaway instances of PBS, MySQLContainer, MockServerContainer containers. And MockServer for mocking external services.
- Install Docker
- Set launchContainers system property to 'true'
mvn clean -B package -DskipUnitTests=true docker:build
- to build image
Don't forget to rebuild image for manual test start (after change in dev code)
- You can use
mvn verify
- to include all previous steps (including java test) because groovy runs infailsafe:integration-test
phase - Or use more granular
mvn -B verify -DskipUnitTests=true
for functional tests only
Functional tests need to have name template .*Spec.groovy
/functional/*Spec
- contain all test suites./functional/util
- different useful methods and wrappers./functional/repository
- interaction with DB. Notice, that some related objects need to use ID generated by DB. Primary Key will be inserted after saving instance into DB./functional/service/PrebidServerService
- responsible for all PBS http calls./functional/testcontainers/Dependencies
- stores dependencies and manages mySql and NetworkServiceContainer containers./functional/testcontainers/ErrorListener
- logs request and response in case of falling test./functional/testcontainers/PbsConfig
- collects PBS properties./functional/testcontainers/PbsServiceFactory
- manage PBS containers according to container limit./functional/testcontainers/PBSTestExtension
- allows to hook into a spec’s lifecycle to add ErrorListener using annotationPBSTest
./functional/testcontainers/TestcontainersExtension
- allow to hook into a spec’s lifecycle to start and stop support service containers using global extension./functional/testcontainers/container
- responsible for creating and configuring containers./functional/testcontainers/scaffolding/NetworkScaffolding
- makes HTTP requests to a MockServer.
Properties:
launchContainers
- responsible for starting the MockServer and the MySQLContainer container. Default value is false to not launch containers for unit tests.
tests.max-container-count
- maximum number of simultaneously running PBS containers. Default value is 2.
skipFunctionalTests
- allow to skip funtional tests. Default value is false.
skipUnitTests
- allow to skip unit tests. Default value is false.
Debug:
An application running inside a Docker container is treated as a remote application, so you can attach the debugger to it.
In order to obtain the debug port you need to use getMappedPort(8000)
based on the desired container.
Every container expose random port which you can see docker ps
- running containers. (add flag -a
to see exited containers)
You can observe logs inside container docker logs <container_id>
. (You don't need to write all id, just use 2-3 symbols)
Container for mocking different calls from PBS: prebid cache, bidders, currency conversion service, PubStack analytics, http data source
/auction
- default mocked bidder call returns response based on information from request:
{
"id":"0a00b9a1-06c0-4001-9d64-b6a3f7d995e6",
"seatbid":[
{
"bid":[
{
"id":"c550cf25-3a09-480b-852f-e75a009bbefd",
"impid":"b9a2756a-6aef-438c-85ed-53331a7b4c53",
"price":1.23,
"crid":"1"
}
]
}
]
}
/cache
- mocked PBC call returns:
{
"responses":[
{
"uuid":"8565b07a-8a64-476b-ac68-cc09b4560625"
}
]
}
Container for Mysql database.
- Use
org/prebid/server/functional/db_schema.sql
script for scheme. - DataBase:
prebid
- Username:
prebid
- Password:
prebid
Starting image prebid/prebid-server:latest
.
Waits for container is ready by checking "/status" endpoint.
TestContainer will start special Ryuk container
which will manage a lifecycle of all depending containers.