【问题标题】:REST assured: Wait for a condition before running all testsREST 保证:在运行所有测试之前等待一个条件
【发布时间】:2020-07-30 16:37:52
【问题描述】:

我有一项服务,当它被加载时,需要一段时间(几分钟),直到所有信息都进入数据库。

如果我过早地运行测试,它们将因此而失败(数据库中缺少项目)。

是否有一些 REST 保证功能来处理它?或者我需要有自己的机制来做到这一点?

【问题讨论】:

    标签: java api testing junit rest-assured


    【解决方案1】:

    除非服务本身提供端点来检查其状态,否则 Rest-Assured 无法确定服务是否已启动。此外,Rest-Assured 不管理测试生命周期。

    但是 JUnit 可以。您可以通过在@BeforeAll@BeforeEach 方法中编写条件逻辑来实现您的需要,如下所示:

    boolean serviceStarted = false;
    
    @BeforeAll
    public void waitForServiceStart(){
        try{
            // Wait for conditions here
            serviceStarted = true;
        }catch (Throwable e){
            // Process exception here
        }
    }
    
    @BeforeEach
    public void makeSureEverythingIsReady(){
        Assumptions.assumeTrue(serviceStarted);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-21
      • 2020-03-04
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多