Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

単体テストでリポジトリに引数が正しく渡されているか検証する #1747

Open
1 task
KentaHizume opened this issue Dec 24, 2024 · 0 comments
Labels
target: Dressca サンプルアプリケーションDresscaに関係がある

Comments

@KentaHizume
Copy link
Contributor

概要

単体テストにおいて、
リポジトリに引数が正しく渡されているかを検証するケースが不足している箇所がある。
該当箇所を調査のうえ、不足しているものについてはケースを追加する。

詳細 / 機能詳細(オプション)

  • たとえば、下図のテストスイートでは、when(this.orderRepository.add(any())).thenReturn(order);
    を用いているため、引数の妥当性を検証できていない。
  @Test
  void testCheckout_正常系_注文リポジトリのAddを1回呼出す() throws Exception {
    // Arrange
    String buyerId = UUID.randomUUID().toString();
    Basket basket = new Basket(buyerId);
    basket.addItem(10L, BigDecimal.valueOf(100_000_000), 1);
    ShipTo shipToAddress = createDefaultShipTo();
    List<CatalogItem> catalogItems = List.of(createCatalogItem(10L));
    Order order = new Order(buyerId, shipToAddress, createDefaultOrderItems());

    when(this.basketRepository.findByBuyerId(buyerId)).thenReturn(Optional.of(basket));
    when(this.catalogRepository.findByCatalogItemIdIn(List.of(10L))).thenReturn(catalogItems);
    when(this.orderRepository.add(any())).thenReturn(order);

    // Act
    service.checkout(buyerId, shipToAddress);

    // Assert
    verify(this.orderRepository, times(1)).add(any());
    verify(this.basketRepository, times(1)).findByBuyerId(buyerId);
    verify(this.basketRepository, times(1)).remove(basket);

  }

完了条件

  • 単体テストでリポジトリに引数が正しく渡されているか検証できていること
@KentaHizume KentaHizume added the not triaged 精緻化、分析がされていない label Dec 24, 2024
@tsuna-can-se tsuna-can-se added target: Dressca サンプルアプリケーションDresscaに関係がある and removed not triaged 精緻化、分析がされていない labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target: Dressca サンプルアプリケーションDresscaに関係がある
Projects
None yet
Development

No branches or pull requests

2 participants