问题
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