title: Testing Spring Boot Actuator endpoint without starting full application
body: <p>My Spring Boot application is configured with a datasource and exposes the Spring Actuator health and prometheus metrics.</p>
  <p><strong>application.yml</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>spring:
    datasource:
      driver-class-name: org.mariadb.jdbc.Driver
      username: ${db.username}
      password: ${db.password}
      url: jdbc:mariadb://${db.host}:${db.port}/${db.schema}
  
  management:
    endpoints:
      web:
        exposure:
          include: 'health, prometheus'
  </code></pre>
  <p>When starting the application, <code>/actuator/prometheus</code> delivers a response containing metrics. Now I'd like to write a very basic test (JUnit 5) for the <code>prometheus</code> endpoint. This is how it looks at the moment:</p>
  <p><strong>Test Class</strong></p>
  <pre class="lang-java prettyprint-override"><code>@SpringBootTest
  @ExtendWith(SpringExtension.class)
  @AutoConfigureMockMvc
  public class HealthMetricsIT {
  
      @Autowired
      private MockMvc mockMvc;
  
      @Test
      public void shouldProvideHealthMetric() throws Exception {
          mockMvc.perform(get(&quot;/actuator/prometheus&quot;)).andExpect(status().isOk());
      }
  }
  </code></pre>
  <p>However I'm running into two issues here and I don't know yet how to solve them.</p>
  <h3>Issue 1</h3>
  <ul>
  <li>With this setup, the test seems to bring up the whole application, thus trying to connect to a running database.</li>
  <li>The test won't start properly because the datasource properties prefixed with <code>db</code> are not provided.</li>
  </ul>
  <p>How can I start this test without bringing up the database connection?</p>
  <h3>Issue 2</h3>
  <p>Even if my local database is running and I provide all <code>db</code> properties, the test fails. This time because I get a HTTP 404 instead of a 200.</p>