cucumber - cucumber example seems adding more items
问题描述
I wanted to add 3 items, completed 1 of them, then go to filter the 'completed' items.
In the end of execution, I saw more items added. is this constructed wrong?
Feature: filter todo item
As a working adult with busy schedules
I want to use todo app to filter todo item
so that I can check todo item by status
Scenario Outline: Filter todo item
Given my todo list is empty
When I add "First todo item #1"
And I add "next todo item #2"
And I add "next todo item #3"
Then my todo list should has followings:
| <Item Displayed> |
When I complete "First todo item #1"
Then the todo item called "First todo item #1" should be marked as completed
And I filter the list to show Completed tasks
Then my todo list should has followings:
| <Item Displayed> |
Examples:
| Filter | Item Displayed |
| Completed | First todo item #1 |
| Active | next todo item #2 |
| Active | next todo item #3 |
error:
org.junit.ComparisonFailure: expected:<[tru]e> but was:<[fals]e>
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at todos.stepdefinitions.StepDefinitions.theTodoItemCalledShouldBeMarkedAsCompleted(StepDefinitions.java:88)
at ✽.the todo item called "First todo item #1" should be marked as completed
this is the steps definitions:
public class StepDefinitions {
@Steps
AddNewTodoActions addTodo;
@Steps
TodoListActions todoItems;
@Given("(?:.*) todo list is empty")
public void fresh_todo() {
navigate.toTheTodoMVCApplication();
}
@When("I add {string}")
public void i_add(String todoItem) {
addTodo.itemCalled(todoItem);
}
@Then("(?:.*) todo list should has followings:")
public void todo_list_should_has_followings(List<String> expectedItems) {
assertThat(todoItems.currentItems()).containsAll(expectedItems);
}
@And("the remaining item count is displayed as {string}")
public void remaining_item_count_displayed(String remainingItemCountText) {
assertThat(todoItems.numberOfItemsLeftMessage()).isEqualTo(remainingItemCountText);
}
@Given("I have a todo list containing")
public void has_a_list_containing(List<String> expectedItems) {
navigate.toTheTodoMVCApplication();
addTodo.itemsCalled(expectedItems);
}
@Steps
FilterItemsActions filterItems;
@When("I filter the list to show {word} tasks")
public void filtersBy(String filters) {
filterItems.by(filters);
}
@Steps
CompleteTodoActions completeTodo;
@When("I complete {string}")
public void complete(String completedTodo) {
completeTodo.itemCalled(completedTodo);
}
@Then("the todo item called {string} should be marked as completed")
public void theTodoItemCalledShouldBeMarkedAsCompleted(String todoItem) {
assertThat(completeTodo.isCompleted(todoItem)).isTrue();
}
}
the editor suggested me to use scenario outline. so i just go ahead and change it. let me know what should be the correct structure, just using scenario good enough?
解决方案
方案大纲为示例列中的每一行创建一个单独的方案。我建议作为黄瓜的新用户避免使用场景大纲,不需要它们,它们只会使事情复杂化。
我是一名资深的 Cuker(因为在 Cucumber 被命名之前)。我从不使用场景大纲。
从您的问题来看,在我看来,您在这种情况下尝试做的是测试过滤。一个更好的方案会使这一点更清楚。怎么样
Feature: Filtering todo's
Scenario: View completed todo's
Given I have some todo's
And one todo is completed
When I view my todo's
And I filter on completed
Then I should see only my completed todo
注意:我不是在描述如何做任何事情。这是 Cuke 的首选方式。
推荐阅读
- excel - 带有循环目标的 VBA 目标搜索
- typescript - p.$key 在 url 角度 8 中返回未定义
- wpf - 切换子控件时如何在 WPF Datagrid 中保持排序顺序
- reactjs - 在 ReactJs 中不动态刷新依赖的下拉内容
- java - org.hibernate.LazyInitializationException:未能使用 JpaRepository 接口延迟初始化角色集合
- html - 使用 excel Visual Basic 脚本进行网页抓取
- javascript - 反应。从服务器获取数据并将其连接到 i18n
- git - Git 保留原始文件,不跟踪对它的任何更改
- java - 使用 Jena API 检索 Ontology IRI
- c# - TCPClient 和 TCPListener 只监听不发送