Skip to content

Naming Conventions

ChernenkoVitaliy edited this page Dec 10, 2024 · 5 revisions

Naming Convention for Test Methods

When naming test methods, we follow a specific convention to ensure clarity and consistency. The convention is based on the idea of describing the feature or functionality being tested.

Format: featureTestScenario

feature: A brief description of the feature or functionality being tested, such as "Event Ownership", "Create Habit", "Get Comment", etc.

TestScenario: A phrase that describes the specific scenario or condition under which the test is being performed, such as "For Valid Event and User", "With Invalid Habit Data", "For Comment with Valid ID", etc.

For the end of each method name word Test should be added. This convention helps developers quickly identify test methods and other methods in the code while using search, which can save time and not distract.

Examples:

Example methods:
boolean isEventOwner(Event event, User user) {...}
HabitDto createHabit(HabitCreatioDto habit, User user) {...}
CommentDto getCommentById(ArticleType type, Long id, UserVO userVO) {...}

isEventOwnerForValidEventAndUserTest: This test method checks that the isEventOwner method returns true when the user is the valid event owner.
isNotEventOwnerIfUserIsNotCreatedEventTest: This test method checks that the isEventOwner method returns false when the user is not the valid event owner.
createHabitWithValidDataSucceedsTest: This test method checks that the createHabit method succeeds and returns a valid habit when the habit data is valid.
createHabitWithInvalidDataFailsTest: This test method checks that the createHabit method fails or returns an error when the habit data is invalid.
createHabitThrowsNotFoundExceptionIfUserNotFoundTest: This test method checks that the createHabit method throws a NotFoundException when the user does not exist.
getCommentByIdReturnsCommentForValidCommentIdTest: This test method checks that the getCommentById method returns the correct comment when the comment ID is valid.
getCommentByIdReturnsNullForInvalidCommentIdTest: This test method checks that the getCommentById method returns null when the comment ID is invalid.

This convention helps to create clear and concise test method names that accurately describe the feature being tested and the specific scenario or condition under which the test is being performed. It also makes it easier to understand the purpose of each test method and ensures consistency across the test suite.

Git branches naming

Prefixes
 	- bug
	- doc       - to add some documentation 
	- feature
	- test
	- migration - for sql scripts

 - Example ->  bug/234/fix-something
                |   |            |
            prefix  issue       message