Video in progress
When is it reasonable to use the @Disabled annotation, and what makes it risky?
@Disabled switches a test off temporarily, for example while an external service is down. The risk is that a disabled test gets forgotten, and the bug it was supposed to catch quietly goes to prod.
📖 Answer
@Disabled("PAY-412: provayder sandbox'i ishlamayapti, 15-noyabrgacha")
@Test
void tolov_sandboxda_otadi() { ... }
You must write the reason: a @Disabled with no reason is still sitting there a year later, and nobody knows why it was disabled.
In practice there are often better options:
- conditional disabling:
@EnabledOnOs(OS.LINUX),@EnabledIfEnvironmentVariable(named = "CI", matches = "true"); - if there's no Docker for Testcontainers,
@Testcontainers(disabledWithoutDocker = true); assumeTrue(...)inside the test: if the condition isn't met, the test is "skipped" rather than failed.
On one project they marked flaky tests @Disabled with "we'll fix them later"; half a year later there were 40 disabled tests. That's why many teams track the number of disabled tests in CI, or require a ticket number on each one.
Sign up to mark studied questions and save your progress.