티스토리 뷰

이 글은 단위 테스트 네이밍 시 따를 수 있는 네이밍 전략을 정리한 목록으로, 여러 페이지를 훑어보는 대신 빠르게 간략한 정보들을 참고하기 위한 레퍼런스성 글이다. 더 자세한 내용을 보려면 아래 링크된 페이지를 참고 바란다.


다음은 위 페이지의 내용을 간략하게 정리한 7가지 인기 단위 테스트 네이밍 전략이다.

  1. 메서드명_테스트상태_기대결과

    • 코드 리팩터링으로 인하여 메서드명이 변경되는 경우 테스트명 또한 변경되어야 하는데, 변경되지 않으면 나중에 이 TC를 이해하기 어렵게 되므로, 바람직하지 않다는 의견이 있다.
    • 예시
      • isAdult_AgeLessThan18_False
      • withdrawMoney_InvalidAccount_ExceptionThrown
      • admitStudent_MissingMandatoryFields_FailToAdmit
  2. 메소드명_기대결과_테스트상태

    • 1번과 비슷한 형태이지만, 일부 개발자들은 이런 컨벤션을 사용할 것을 추천한다. 이 컨벤션 또한 메서드명이 바뀌면 나중에 이해하기 어렵다는 단점이 있다.
    • 예시
      • isAdult_False_AgeLessThan18
      • withdrawMoney_ThrowsException_IfAccountIsInvalid
      • admitStudent_FailToAdmit_IfMandatoryFieldsAreMissing
  3. test[테스트할 기능]

    • 테스트할 기능이 테스트명의 일부로 사용되어 쉽게 읽을 수 있도록 해 준다. 그러나 "테스트" 접두사가 중복된다는 주장도 있다. 그러나 일부 개발자들은 이러한 형태의 네이밍을 사용하는 것을 좋아한다.
    • 예시
      • testIsNotAnAdultIfAgeLessThan18
      • testFailToWithdrawMoneyIfAccountIsInvalid
      • testStudentIsNotAdmittedIfMandatoryFieldsAreMissing
  4. 테스트할 기능

    • 테스트 메서드를 식별하는 방법으로 주석을 사용하고 있기 때문에, 테스트할 기능만 간단하게 쓰는 것이 더 낫다는 의견이 많다. 또한 코드의 악취를 방지하고, 문서화된 형태의 유닛 테스트를 수행하므로 권장되는 방법이다.
    • 예시
      • IsNotAnAdultIfAgeLessThan18
      • FailToWithdrawMoneyIfAccountIsInvalid
      • StudentIsNotAdmittedIfMandatoryFieldsAreMissing
  5. should_기대결과_When_테스트상태

    • 이러한 형태의 네이밍은 많은 사람들이 테스트에 대해 쉽게 이해할 수 있기 때문에 많이 사용된다.
    • 예시
      • should_ThrowException_When_AgeLessThan18
      • should_FailToWithdrawMoney_ForInvalidAccount
      • should_FailToAdmit_IfMandatoryFieldsAreMissing
  6. when_테스트상태_Expect_기대결과

    • 예시
      • When_AgeLessThan18_Expect_isAdultAsFalse
      • When_InvalidAccount_Expect_WithdrawMoneyToFail
      • When_MandatoryFieldsAreMissing_Expect_StudentAdmissionToFail
  7. given_사전조건_When_테스트상태_Expect_기대결과

    • 이러한 접근법은 행동 주도 개발(BDD)의 일부로 개발된 네이밍 컨벤션에 기초한다. 이 아이디어는 테스트를 세개의 파트로 나누어 전제 조건, 테스트 상태, 기대 결과가 위 형식대로 네이밍되는 형태이다.
    • 예시
      • Given_UserIsAuthenticated_When_InvalidAccountNumberIsUsedToWithdrawMoney_Then_TransactionsWillFail

원문 링크 - https://dzone.com/articles/7-popular-unit-test-naming

 

7 Popular Unit Test Naming Conventions - DZone Agile

The article presents a compiled list of unit tests naming strategy that one could follow for naming their unit tests. The article is intended to be a quick...

dzone.com

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함