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 the tests in two different environments, environment A and B. In environment A, i want SpringBootTest to start up the server on a random port and then run the test, that is why i am setting webEnvironment attribute. However, in environment B, i want to run the same test without starting the server (i will be calling the deployed server in the testing environment directly).

Is there a way to enable/disabled webEnvironment attribute based on an input, for example using ActiveProfile, environment property or anything that i can pass to the test.

Any suggestion how i can achieve this.

来源:https://stackoverflow.com/questions/51539714/springboottest-enable-disable-webenvironment-based-on-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!