Given, When, Then

Given-When-Then is a style of representing tests specifying a system’s behavior. It’s an approach developed by Dan North and Chris Matts as part of Behavior-Driven Development (BDD). It appears as a structuring approach for many testing frameworks such as Cucumber. You can also look at it as a reformulation of the Four-Phase Test pattern. The essential idea is to break down writing a scenario (or test) into three sections: The given part describes the state of the world before you begin the behavior you’re specifying in this scenario. You can…

Read More

7 Popular Unit Test Naming Conventions

Following are 7 popular unit tests naming conventions that are found to be used by majority of developers and compiled from above pages: MethodName_StateUnderTest_ExpectedBehavior: There are arguments against this strategy that if method names change as part of code refactoring than test name like this should also change or it becomes difficult to comprehend at a later stage. Following are some of the example: isAdult_AgeLessThan18_False withdrawMoney_InvalidAccount_ExceptionThrown admitStudent_MissingMandatoryFields_FailToAdmit MethodName_ExpectedBehavior_StateUnderTest: Slightly tweeked from above, but a section of developers also recommend using this naming technique. This technique also has disadvantage that if…

Read More