spring-boot-test

Appropriate usage of TestPropertyValues in Spring Boot Tests

♀尐吖头ヾ 提交于 2020-06-26 04:52:34
问题 I came across TestPropertyValues , which is briefly mentioned in the Spring Boot docs here: https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc#testpropertyvalues It's also mentioned in the Migration Guide here: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#environmenttestutils Both examples show an environment variable to apply the properties to, but there's no other

Appropriate usage of TestPropertyValues in Spring Boot Tests

家住魔仙堡 提交于 2020-06-26 04:52:31
问题 I came across TestPropertyValues , which is briefly mentioned in the Spring Boot docs here: https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc#testpropertyvalues It's also mentioned in the Migration Guide here: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#environmenttestutils Both examples show an environment variable to apply the properties to, but there's no other

Tests not working for multiple datasource with spring boot liquibase

落爺英雄遲暮 提交于 2020-04-17 22:41:35
问题 I am creating unittesting for spring boot application having multiple datasources. (Configuration is heavily inspired from this answer) @Configuration public class DatasourceConfig { @Primary @Bean @ConfigurationProperties(prefix = "datasource.primary") public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } @Bean @ConfigurationProperties(prefix = "datasource.primary.liquibase") public LiquibaseProperties primaryLiquibaseProperties() { return new

Tests not working for multiple datasource with spring boot liquibase

▼魔方 西西 提交于 2020-04-17 22:41:11
问题 I am creating unittesting for spring boot application having multiple datasources. (Configuration is heavily inspired from this answer) @Configuration public class DatasourceConfig { @Primary @Bean @ConfigurationProperties(prefix = "datasource.primary") public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } @Bean @ConfigurationProperties(prefix = "datasource.primary.liquibase") public LiquibaseProperties primaryLiquibaseProperties() { return new

Difference between junit-vintage-engine and junit-jupiter-engine?

情到浓时终转凉″ 提交于 2020-03-23 11:55:09
问题 It's a two-fold question. What is the difference between junit-vintage-engine and junit-jupiter-engine ? SpringBoot starter projects come with an exclusion for junit-vintage-engine . Is it to enforce the use of junit-jupiter-engine? Below is the dependency of my SpringBoot project generated from Spring Initializr: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage<

Creating integration tests in a monolithic SpringBoot application

℡╲_俬逩灬. 提交于 2020-03-16 08:17:52
问题 I was asked to create an integration test for a service within a very large SpringBoot project yielding dozens of implemented services. When the application is executed all of these services are deployed - I want to avoid deploying all services unrelated with the one for which I'm creating the test. Unfortunately, I do not (yet) have as much experience with spring boot tests as I would hope for hence I was wondering what is the best approach to address this. I was thinking about annotating

SpringRunner vs SpringBootTest

别来无恙 提交于 2020-02-01 05:08:25
问题 In unit test, what are the differences between @Runwith(SpringRunner.class) & @SpringBootTest ? Can you explain to me the use cases of each one? 回答1: @RunWith(SpringRunner.class) : You need this annotation to just enable spring boot features like @Autowire , @MockBean etc.. during junit testing is used to provide a bridge between Spring Boot test features and JUnit. Whenever we are using any Spring Boot testing features in our JUnit tests, this annotation will be required. @SpringBootTest :

SpringBootTest enable/disable webEnvironment based on input

不羁的心 提交于 2020-01-15 09:37:31
问题 I am using Cucumber with SpringBootTest. The following class is used to configure SpringBootTest @ContextConfiguration(classes = Application.class, loader = SpringBootContextLoader.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public abstract class StepDefinition { @LocalServerPort private int port; @Autowired private TestRestTemplate restTemplate; } All step definitions extends this class public class MyStepdefs extends StepDefinition { ...} I need to run

IntegrationTest isolation fails in springboot 2.2.2.RELEASE (Error dopping tables after each SpringBootTest)

元气小坏坏 提交于 2020-01-15 05:41:06
问题 Our app is working in 2.0.4 release. After upgrade to 2.2.2.RELEASE we see integration tests failing. I suspect that there is some misconfiguration, and each integration test simply does not clean after itself or there is extra initialization which weren't here before. I really do not know how to fix it properly. To be specific. Each test works when invoked separately. When executed all of them we do see errors like: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing

IntegrationTest isolation fails in springboot 2.2.2.RELEASE (Error dopping tables after each SpringBootTest)

倾然丶 夕夏残阳落幕 提交于 2020-01-15 05:41:02
问题 Our app is working in 2.0.4 release. After upgrade to 2.2.2.RELEASE we see integration tests failing. I suspect that there is some misconfiguration, and each integration test simply does not clean after itself or there is extra initialization which weren't here before. I really do not know how to fix it properly. To be specific. Each test works when invoked separately. When executed all of them we do see errors like: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing