-
[Java] 인기있는 Unit Test 네이밍 규칙Java 2019. 4. 15. 00:09
다음은 일반적으로 인기있는 7가지 Unit Test 명명 규칙이다.
1. MethodName_StateUnderTest_ExpectedBehavior
예제:
- isAdult_AgeLessThan18_False
- withdrawMoney_InvalidAccount_ExceptionThrown
- admitStudent_MissingMandatoryFields_FailToAdmit
2. MethodName_ExpectedBehavior_StateUndertest
예제:
- isAdult_False_AgeLessThan18
- withdrawMoney_ExceptionThrown_InvalidAccount
- admitStudent_FailToAdmit_MissingMandatoryFields
3. test[Feature being tested]
예제:
- testIsNotAnAdultIfAgeLessThan18
- testFailToWithdrawMoneyIfAccountIsInvalid
- testStudentIsNotAdmittedIfMandatoryFieldAreMissing
4. Feature to be tested
예제:
- IsNotAnAdultIfAgeLessThan18
- FailToWithdrawMoneyIfAccountIsInvalid
- StudentIsNotAdmittedIfMandatoryFieldsAreMissing
5. Should_ExpectedBehavior_When_StateUnderTest
예제:
- Should_ThrowException_When_AgeLessThan18
- Should_FailToWithdrawMoney_ForInvalidAccount
- Should_FailToAdmit_IfMandatoryFieldsAreMissing
6. When_StateUnderTest_Expect_ExpectedBehavior
예제:
- When_AgeLessThan18_Expect_isAdultAsFalse
- When_InvalidAccount_Expect_WithdrawMoneyToFail
- When_MandatoryFieldsAreMissing_Expect_StudentAdmissionToFail
7. Given_Preconditions_When_SateUnderTest_Then_ExpectedBehavior
예제:
- Given_UserIsAuthenticated_When_InvalidAccountNumberIsUsedToWithdrawMoney_Then_TransactionsWillFail
'Java' 카테고리의 다른 글
[Java] Lombok @Data 어노테이션 (0) 2019.05.07 [Java] 정규표현식 기본 문법 (0) 2019.04.23 [Java] 부정을 나타내는 변수명 붙이는 방법 (0) 2019.04.21 [Java] 읽기 쉬운 테스트를 위한 Hamcrest 사용하기 (0) 2019.04.15 [Java] StringUtils.isBlank 와 StringUtils.isEmpty 차이 (2) 2019.04.15 댓글