Short answer
You test a feature behind a feature flag in both flag states: on, to check the new feature, and off, to check that the old path works as before. Add three things that are easy to forget: switching the flag during a user’s session, behaviour when the flag service doesn’t respond, and gradual rollout to part of the users. Don’t test every combination of flags, only those that affect the same feature. Remove flags once fully rolled out, because every old flag is another combination to test.
What to test for every flag
| scenario | what to check |
|---|---|
| flag on | the new feature against its acceptance criteria |
| flag off | the old path unchanged, no traces of the new feature in the UI or API |
| switched during a session | a user halfway through a process doesn’t lose data or see an error |
| flag service unavailable | the app uses a safe default value |
| rollout to part of the users | the right people see the feature, others don’t; the same person sees the same thing on every visit |
| data created with the flag on | still works after the flag is turned off |
The last point is the one most often skipped. If a customer created something in the new feature and the flag is turned off, their data must not disappear or break the old path.
Flag combinations
With 10 flags there are 1,024 combinations. Testing them all makes no sense. Sensible rules:
- each flag in both states, with the others set as in production;
- combinations only for flags that affect the same path, e.g. a new cart and a new payment flow;
- a list of current flags with an owner and a planned removal date.
Flags in automated tests
Each test sets the flags it needs instead of relying on the state of the environment. An example in Playwright, where the app reads flags from a cookie that only works on staging:
test("new cart: discount code", async ({ page, context }) => {
await context.addCookies([
{ name: "ff_new_cart", value: "on", url: process.env.BASE_URL! },
]);
await page.goto("/cart");
// ... new cart scenario
});
It’s worth running the same suite in CI for both states of the flags currently being rolled out. When a flag is removed, you remove that test variant too.
Old flags are debt
A flag that has been on for everyone for six months is dead code and an extra path that someone will one day switch off by accident. Rules:
- every flag has an owner and a removal date;
- after full rollout and 2-4 weeks of stability, the flag is removed;
- removing a flag is a normal sprint task, with a test after removal.
Feature flags are one of the things that let you release often without being blocked by testing. More in how to test with weekly releases.
How I can help
As part of QA support I test features behind flags at your release pace, and as part of test automation I set up E2E tests so they switch flags themselves. Describe how you use flags in the contact form.