在计算器空手道测试中找不到步骤定义方法匹配

问题描述 投票:0回答:1

我正在尝试运行一个空手道测试,将两个数字 10 和 5 相加。但是当我运行测试时,我收到此错误: 鉴于我已输入数字 10 找不到匹配的步骤定义方法:我输入了数字 10 src/test/resources/calc/calculator.feature:4

这是我的计算器.功能文件

Feature: Calculator Functionality

Scenario: Adding two numbers
Given I have entered the number 10
When I press the add button
And I have entered the number 5
Then the result displayed should be 15

我还定义了一个StepDefinitions.java文件

package calc;

import io.cucumber.java.en.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class StepDefinitions {
  private int currentNumber = 0;
  private int result = 0;
  private String operation = "";

  @Given("I have entered the number {int}")
  public void i_have_entered_the_number(int number) {
    currentNumber = number;
  }

  @When("I press the add button")
  public void i_press_the_button() {
    operation = "add";
  }

  @And("I have entered the number {int}")
  public void i_have_entered_another_number(int number) {
    if (operation.equals("add")) {
      result = currentNumber + number;
    }
  }

  @Then("the result displayed should be {int}")
  public void the_result_displayed_should_be(int expectedResult) {
    assertEquals(expectedResult, result);
  }
}
java karate
1个回答
0
投票

这似乎是格式问题。缩进应该在场景行之后。

Feature: Calculator Functionality

Scenario: Adding two numbers
  Given I have entered the number 10
  When I press the add button
  And I have entered the number 5
  Then the result displayed should be 15
© www.soinside.com 2019 - 2024. All rights reserved.