terrydiederich2
1/10/2019 - 3:31 PM

Unit Testing Naming Convention

Should_ExpectedBehavior_When_StateUnderTest:
This technique is also used by many as it makes it easy to read the tests. Following is how tests in first example would read like if named using this technique:

  • Should_ThrowException_When_AgeLessThan18
  • Should_FailToWithdrawMoney_ForInvalidAccount
  • Should_FailToAdmit_IfMandatoryFieldsAreMissing

From https://dzone.com/articles/7-popular-unit-test-naming

**[method]_Should[expected]_When[condition]
Deposit_ShouldIncreaseBalance_WhenGivenPositiveValue()

From https://stackoverflow.com/questions/155436/unit-test-naming-best-practices?rq=1