【问题标题】:How to configure to run the springboot tests against an already up and running service on a different location如何配置以针对不同位置上已启动并正在运行的服务运行 springboot 测试
【发布时间】:2015-09-14 06:40:15
【问题描述】:

我必须配置我的集成测试以针对在不同位置启动并运行的服务运行。目前我的测试是针对 localhost 的,它们通过父类中定义的以下注释启动服务:

@SpringApplicationConfiguration(classes =ServiceApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:8084")

在子类中,这是我配置测试以获取端口和端点来运行测试的方式:

@RunWith(SpringJUnit4ClassRunner.class)
public class RunningIntegrationIT extends BaseTestService {

    @Value("${local.server.port}")
    int port;
    private String uri = "/service/firstName";

    @Before
    public void setup() {
        RestAssured.port = port;
    }

现在,如果我必须针对已经在不同 ipaddress 和端口上运行的服务运行测试,那么如何配置该设置。好像如果我使用@IntegrationTest 它默认启动spring-boot tomcat。

我也读过使用@ActiveProfile,但有人可以给我详细说明如何使用这个注释。

【问题讨论】:

    标签: spring-boot rest-assured


    【解决方案1】:

    local.server.port 包含local。您不能只使用它来指代您希望运行的不同进程。你的测试变成了纯粹的客户端测试,所以也许他们根本不应该使用 spring boot。

    您在测试中使用了什么自动配置部件?也许使用 Spring Boot 并没有带来什么好处?

    我了解您可能希望在 Spring Boot 将启动的服务和远程实例之间共享相同的测试套件。没关系:只需在抽象类中编写测试并有两个实现。完整的远程甚至可能不使用 Spring Boot。

    【讨论】:

    • 谢谢@Stephane,你能举个例子解释一下吗?
    • 具体解释一下?
    • 所以我能够通过创建一个属性文件并在基类中读取它来实现我想要的。我删除了 local.server.port,因为它只是在本地启动服务并在 @Before 中设置端口
    猜你喜欢
    • 2018-09-24
    • 1970-01-01
    • 2017-08-07
    • 2019-10-14
    • 2019-07-15
    • 2020-05-23
    • 2023-03-24
    • 2014-11-24
    • 2018-05-28
    相关资源
    最近更新 更多