JUnit’s @TestMethodOrder annotation not working

You need to configure correctly your IDE. Requirements <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.4.0</version> </dependency> Do not use JUnit 5 that offers your IDE. If you add it as library, you will get: No tests found for with test runner ‘JUnit 5’ ==================== and this exception =================== TestEngine with ID ‘junit-vintage’ failed to discover tests java.lang.SecurityException: class … Read more

/actuator/prometheus missing in @SpringbootTest

Update: @Thierry mentioned @AutoConfigureMetrics is deprecated and one needs to use the @AutoConfigureObservability annotation instead. See his post! Original post: I faced the same issue. After some tracing through spring-context ConditionEvaluator, I found that the newly introduced @ConditionalOnEnabledMetricsExport(“prometheus”) condition on PrometheusMetricsExportAutoConfiguration prevented the endpoint from loading. This is intended behavior due to https://github.com/spring-projects/spring-boot/pull/21658 and impacts … Read more

How to reuse Testcontainers between multiple SpringBootTests?

You can’t use the JUnit Jupiter annotation @Container if you want to have reusable containers. This annotation ensures to stop the container after each test. What you need is the singleton container approach, and use e.g. @BeforeAll to start your containers. Even though you then have .start() in multiple tests, Testcontainers won’t start a new … Read more

What’s the difference between @AutoConfigureWebMvc and @AutoConfigureMockMvc?

@AutoConfigureWebMvc Use this if you need to configure the web layer for testing but don’t need to use MockMvc It enables all auto-configuration related to the web layer and ONLY the web layer. This is a subset of overall auto-configuration. It includes the following auto-configuration (see spring.factories) # AutoConfigureWebMvc auto-configuration imports org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc=\ org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\ org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\ … Read more

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

junit-vintage-engine is used for running JUnit 4 tests; junit-jupiter-engine for JUnit 5 tests. Presumably since you’ll be writing only JUnit 5 tests for a new Spring Boot project, the vintage engine won’t be needed, hence the default dependency exclusion in the POM. Reference: https://junit.org/junit5/docs/current/user-guide

SpringBootTest : No qualifying bean of type ‘org.springframework.test.web.servlet.MockMvc’ available:

Hope you have spring-boot-starter-web dependency. Not sure which version of Spring boot you use, but build mockMvc this way instead? @RunWith(SpringRunner.class) @SpringBootTest public class ApplicationTest { @Autowired private WebApplicationContext webApplicationContext; private MockMvc mockMvc; @Before public void setUp() { mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); }

SpringRunner vs SpringBootTest

@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 : This annotation is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)