-
Notifications
You must be signed in to change notification settings - Fork 0
Writing Tests in WDS
Add @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
to every unit test that spins up a Hikari connection pool. This should help to clean up the connection pools and avoid problems with hitting max connections to Postgres when running unit tests.
When possible, specify only the config classes that are necessary for your test class with @SpringBootTest(classes = {InstanceInitializerConfig.class, MockInstanceDaoConfig.class})
(for example). This also helps avoid hitting max connections. See
https://github.com/DataBiosphere/terra-workspace-data-service/pull/188
@ActiveProfiles({"mock-instance-dao", "local"})
@ContextConfiguration
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Most tests can extend TestBase, which sets some properties including twds.instance.workspace-id
. TestBase
is also explicitly set to be a data-plane
test; it may be useful to extend this class for a control-plane
test but in order to avoid using both data-plane
and control-plane
you should set inheritProfiles = false
like so: @ActiveProfiles(value = "control-plane", inheritProfiles = false)
TestDao
is used when you need to query the database directly for the purpose of a test.