Cucumber Data Tables

  • 데이터 테이블을 변환하는 3 가지 방법

    • a list of lists (가장 기본)

    • a list of maps

    • a table transformer

Scenario

Scenario: Correct non-zero number of books found by author by list
  Given I have the following books in the store by list
    | The Devil in the White City          | Erik Larson |
    | The Lion, the Witch and the Wardrobe | C.S. Lewis  |
    | In the Garden of Beasts              | Erik Larson |
  When I search for books by author Erik Larson
  Then I find 2 books

Hook

public class BookStoreRunSteps {
    private BookStore store;
    private List<Book> foundBooks;
    
    @Before
    public void setUp() {
        store = new BookStore();
        foundBooks = new ArrayList<>();
    }

    // When & Then definitions ...
}

방법 1 - a list of lists

Cucumber는 각 행을 열 값의 목록으로 처리하여 위의 테이블을 목록의 목록으로 변환합니다.

변환된 형태

코드

방법 2 - a list of maps

변환된 형태

코드

방법 3 - a table transformer

  • 과정: DataTable -> 변환기 (BookTableTransformer) -> 원하는 객체 (BookCatalog)

  • TypeRegistryConfigurer 인터페이스를 구현하는 클래스 만들기

    • configureTypeRegistry() 로 구현체 등록하기

  • 주의

    • 나라에 맞게 locale 변경해야됨

      • BookStoreRegistryConfigurer 클래스에서 locale()를 오버라이드 하여, English locale로 반환 부분

코드

보조 코드

참고 자료

  • https://www.baeldung.com/cucumber-data-tables

Last updated