Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAI Profile overhaul #397

Merged
merged 1 commit into from
Sep 4, 2023
Merged

HAI Profile overhaul #397

merged 1 commit into from
Sep 4, 2023

Conversation

corvidian
Copy link
Contributor

Description

Remove the profiles from Configuration and IntegrationTestConfiguration. Configuration is enabled by default, and we import IntegrationTestConfiguration explicitly when we use it.

This frees us to use the test profile in all tests, especially integration tests. This means we can use application-test.properties for configuring the test environment. This, in turn, means we don't have to configure the main application.properties specifically for tests and we can use production-safe defaults.

Jira Issue: -

Type of change

  • Bug fix
  • New feature
  • Other

Checklist:

  • I have written new tests (if applicable)
  • I have ran the tests myself (if applicable)
  • I have made necessary changes to the documentation, link to confluence
    or other location:

Remove the profiles from Configuration and IntegrationTestConfiguration.
Configuration is enabled by default, and we import
IntegrationTestConfiguration explicitly when we use it.

This frees us to use the test profile in all tests, especially
integration tests. This means we can use application-test.properties for
configuring the test environment. This on turn means we don't have to
configure the main application.properties specifically for tests and we
can use production-safe defaults.
@corvidian corvidian force-pushed the HAI/profile-overhaul branch from b98718f to 3555473 Compare September 1, 2023 14:31
@sonarcloud
Copy link

sonarcloud bot commented Sep 1, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@corvidian corvidian merged commit 86012b9 into dev Sep 4, 2023
4 checks passed
@corvidian corvidian deleted the HAI/profile-overhaul branch September 4, 2023 07:42
corvidian added a commit that referenced this pull request Nov 20, 2023
Configure the Spring Context in integration tests to use a mockk
instance of CableReportService so the mock can be `@Autowired`.
CableReportService was defined in several integration tests as a
`@MockkBean` dependency. The actual implementation was only used in
`CableReportServiceITests`, which constructs its own custom instance.

The other class that was injected with `@MockkBean` was
`EmailSenderService`. Since there's an easy-to-use extension for mocking
an actual email server, it felt better to use that instead of mocking
the service universally. Also, unlike `CableReportServiceITests`,
`EmailSenderServiceITest` uses the Spring context, so a context with the
actual implementation is needed anyway.

Each unique combination of `@MockkBeans` and `@SpykBeans` (or the Mockito
equilevants) makes Spring create a new context for the test. While not
a huge time sink, creating (and destroying) the contexts adds up. We can
clearly see how many different contexts are created from the number of
SQL connection pools that need to be shut down at the end of the tests.

There are situations when they have to be used, but using alternative
approaches is usually better.

New contexts are also created whenever the configuration parameters are
different between tests. This is sometimes unavoidable when we need to
test how the application behaves with different configurations.

Ever since #397 we've been able to use application.test.properties to
configure the test environment, so we don't need to use test-specific
properties to diverge from the production configuration. There was a
properties parameter like remaining in `TestDataServiceITest`, so that
was removed.

There's one more service test with custom properties
(`EmailSenderServicePropertiesITest`), but in that test we're interested
in testing that the properties have the effect we want. And the
properties are different from how we generally want to configure
EmailSenderService in tests. So the custom properties are unavoidable.

Controller tests are cheaper to create with varying configurations.
Since only a very limited context is created for running them,
recreating it is not very expensive. So testing things like feature
flags on the controller level doesn't seem problematic.
corvidian added a commit that referenced this pull request Nov 24, 2023
Configure the Spring Context in integration tests to use a mockk
instance of CableReportService so the mock can be `@Autowired`.
CableReportService was defined in several integration tests as a
`@MockkBean` dependency. The actual implementation was only used in
`CableReportServiceITests`, which constructs its own custom instance.

The other class that was injected with `@MockkBean` was
`EmailSenderService`. Since there's an easy-to-use extension for mocking
an actual email server, it felt better to use that instead of mocking
the service universally. Also, unlike `CableReportServiceITests`,
`EmailSenderServiceITest` uses the Spring context, so a context with the
actual implementation is needed anyway.

Each unique combination of `@MockkBeans` and `@SpykBeans` (or the Mockito
equilevants) makes Spring create a new context for the test. While not
a huge time sink, creating (and destroying) the contexts adds up. We can
clearly see how many different contexts are created from the number of
SQL connection pools that need to be shut down at the end of the tests.

There are situations when they have to be used, but using alternative
approaches is usually better.

New contexts are also created whenever the configuration parameters are
different between tests. This is sometimes unavoidable when we need to
test how the application behaves with different configurations.

Ever since #397 we've been able to use application.test.properties to
configure the test environment, so we don't need to use test-specific
properties to diverge from the production configuration. There was a
properties parameter like remaining in `TestDataServiceITest`, so that
was removed.

There's one more service test with custom properties
(`EmailSenderServicePropertiesITest`), but in that test we're interested
in testing that the properties have the effect we want. And the
properties are different from how we generally want to configure
EmailSenderService in tests. So the custom properties are unavoidable.

Controller tests are cheaper to create with varying configurations.
Since only a very limited context is created for running them,
recreating it is not very expensive. So testing things like feature
flags on the controller level doesn't seem problematic.
corvidian added a commit that referenced this pull request Nov 24, 2023
Configure the Spring Context in integration tests to use a mockk
instance of CableReportService so the mock can be `@Autowired`.
CableReportService was defined in several integration tests as a
`@MockkBean` dependency. The actual implementation was only used in
`CableReportServiceITests`, which constructs its own custom instance.

The other class that was injected with `@MockkBean` was
`EmailSenderService`. Since there's an easy-to-use extension for mocking
an actual email server, it felt better to use that instead of mocking
the service universally. Also, unlike `CableReportServiceITests`,
`EmailSenderServiceITest` uses the Spring context, so a context with the
actual implementation is needed anyway.

Each unique combination of `@MockkBeans` and `@SpykBeans` (or the Mockito
equilevants) makes Spring create a new context for the test. While not
a huge time sink, creating (and destroying) the contexts adds up. We can
clearly see how many different contexts are created from the number of
SQL connection pools that need to be shut down at the end of the tests.

There are situations when they have to be used, but using alternative
approaches is usually better.

New contexts are also created whenever the configuration parameters are
different between tests. This is sometimes unavoidable when we need to
test how the application behaves with different configurations.

Ever since #397 we've been able to use application.test.properties to
configure the test environment, so we don't need to use test-specific
properties to diverge from the production configuration. There was a
properties parameter like remaining in `TestDataServiceITest`, so that
was removed.

There's one more service test with custom properties
(`EmailSenderServicePropertiesITest`), but in that test we're interested
in testing that the properties have the effect we want. And the
properties are different from how we generally want to configure
EmailSenderService in tests. So the custom properties are unavoidable.

Controller tests are cheaper to create with varying configurations.
Since only a very limited context is created for running them,
recreating it is not very expensive. So testing things like feature
flags on the controller level doesn't seem problematic.
corvidian added a commit that referenced this pull request Nov 24, 2023
Configure the Spring Context in integration tests to use a mockk
instance of CableReportService so the mock can be `@Autowired`.
CableReportService was defined in several integration tests as a
`@MockkBean` dependency. The actual implementation was only used in
`CableReportServiceITests`, which constructs its own custom instance.

The other class that was injected with `@MockkBean` was
`EmailSenderService`. Since there's an easy-to-use extension for mocking
an actual email server, it felt better to use that instead of mocking
the service universally. Also, unlike `CableReportServiceITests`,
`EmailSenderServiceITest` uses the Spring context, so a context with the
actual implementation is needed anyway.

Each unique combination of `@MockkBeans` and `@SpykBeans` (or the Mockito
equilevants) makes Spring create a new context for the test. While not
a huge time sink, creating (and destroying) the contexts adds up. We can
clearly see how many different contexts are created from the number of
SQL connection pools that need to be shut down at the end of the tests.

There are situations when they have to be used, but using alternative
approaches is usually better.

New contexts are also created whenever the configuration parameters are
different between tests. This is sometimes unavoidable when we need to
test how the application behaves with different configurations.

Ever since #397 we've been able to use application.test.properties to
configure the test environment, so we don't need to use test-specific
properties to diverge from the production configuration. There was a
properties parameter like remaining in `TestDataServiceITest`, so that
was removed.

There's one more service test with custom properties
(`EmailSenderServicePropertiesITest`), but in that test we're interested
in testing that the properties have the effect we want. And the
properties are different from how we generally want to configure
EmailSenderService in tests. So the custom properties are unavoidable.

Controller tests are cheaper to create with varying configurations.
Since only a very limited context is created for running them,
recreating it is not very expensive. So testing things like feature
flags on the controller level doesn't seem problematic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants