Skip to content

Dynamic SpringBootTest properties #7759

@codefromthecrypt

Description

@codefromthecrypt

There's currently means to assign a dynamic port to the Spring Boot Server under test. When doing micro-integration (side-effect) tests, we a dynamic endpoint for a dependent services. For example, I want to start a fake google service and have Spring Boot use the endpoint to that. Currently, it is not straightforward to wire in a dynamic property like "cloud.endpoint". Neither is it possible for SpringBootTest to pick extra ports: if SpringBootTest could pick other ports, then it could render these as properties, which the fake servers could use in the test.

like here's one idea..

@SpringBootTest(bootstrapProperties = AssignGooglePort.class, ...)
--snip--

static class AssignGooglePort implements Something {
  @Override public void someCallback(ConfigurableApplicationContext context){
    int port = somePortPicker.pick();
    EnvironmentTestUtils.addEnvironment(context,
        "google.endpoint:http://host1:"+port
    );
  }
}

// then the test could read the bootstrapped property by injecting it

Regardless of the solution pattern, it would be great to have SpringBootTest collaborate with other services (which themselves may or may not be Spring Boot).

cc @denyska @marcingrzejszczak

openzipkin/zipkin-gcp#16 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions