Spring Boot actuator health test works from intellij, but not circleci


My circleci gradle build fails for the following test, when health() is called. The error says “org.junit.ComparisonFailure: expected:<[200]> but was:<[503]>”

   private int port;

   private String actuatorUrl(String endpoint) {
       return "http://localhost:" + port + "/actuator/" + endpoint;    }

    public void health() {
        HttpResponse response = httpClient.get(actuatorUrl("health"));


                .withFailMessage("The body is " + response.getBody())

The build runs successfully within intellij.
It also runs successfully form the command line “./gradlew build”.
I’m running circleci locally, but I get the same failure if I check-in to our github repo.
I’m using OpenJDK 11, Spring Boot 2, and Mac Mohave.

This seems to point to a circleci configuration problem, but any thoughts or ideas are greatly appreciated.


“org.junit.ComparisonFailure: expected:<[200]> but was:<[503]>”

Looks like the service isn’t up to respond 200 yet when you assert your test.
A thing I do in my tests using npx is to wait-on the service before running, which might be functionally similar to what you need to do.
Ignoring the health check does it work and respond as you’d expect?

It looks like your code could do with a bit of formatting. That will help folks helping you with your immediate problem, and also will aid readers looking at posts here in the future. Would you edit your post to fix this?

The Markdown syntax for code formatting is:

code goes here

Thank you, I blocked the code with ```.

Thank you! I think this is the problem. The test is running before the service starts in circleci. I’m working on refactoring the workflow.
It was working locally because intellij bootstrap starts the service even to run just one test, then shuts it down.

1 Like