Video in progress
What do you pay attention to when naming test methods, and why is @DisplayName useful?
A test name should say what is expected in which situation, for example bosh_savatda_chegirma_qollanmaydi. @DisplayName shows a readable name in the report, with spaces and any characters.
📖 Answer
Names like test1() and testCalculate() tell you nothing when they fail. If you see "testCalculate FAILED" in CI, you don't know what broke until you open the code.
A good name says three things: what is being tested, under what conditions, and what is expected.
@Test
void transfer_balans_yetmasa_rad_etiladi() { ... }
@Test
@DisplayName("Balans yetmasa o'tkazma rad etiladi")
void insufficientBalance() { ... }
With the second approach, readable text shows up in the IDE and the Surefire report. If you put @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) on the class, the _ in method names automatically turns into spaces, so you don't have to write @DisplayName on every method.
Whichever style you pick, keep it consistent across the team. Mixed names make the report harder to read.
Sign up to mark studied questions and save your progress.