Is Cucumber Worth It?

Learn about Cucumber's worth, uses, and tips.

Cucumber’s worth

Cucumber’s worth depends on what “it” is. Cucumber is a beneficial acceptance-test framework, provided our expectations of it are reasonable. It’s a lousy unit-test framework, and if we try to use it for unit testing, we’ll hate it and will possibly stop eating salads to avoid cucumbers, which is bad for our health.

We should use Cucumber for the relatively minimal goals of writing integration tests at the level of user behavior and separating slower integration tests from faster unit tests easily. For those things, it works great.

Cucumber non-developer participation

We’ll sometimes hear that Cucumber allows non-developer members of our team to participate in the acceptance-testing process because Cucumber is close to natural language. We would have some success with writing Cucumber scenarios on our own and giving them to managers or clients for approval. Going the other direction, the limiting factor that we would experience is not the syntax but rather experience with how to specify requirements. That’s tricky for everybody.

Suppose we use Cucumber for the relatively minimal goals of writing the integration tests at the level of user behavior and being able to easily separate our slower integration tests from the faster unit tests. For those things, it works great.

Cucumber tips

Some tips to use Cucumber better:

  • Write the natural language scenario that defines the system’s behavior from the user perspective. Smooth out details in the step definition.

  • Avoid anything in the feature file that looks like code or data, including CSS selectors and database attributes.

  • Keep step definitions simple.

  • Don’t worry about duplicating bits of step logic. Prefer multiple simple steps over one big step with complex logic.

  • Specify what isn’t on the page, because that’s often as important as specifying what is.

  • Worry about implementation details in the unit tests. The suggestions about what is an integration test and what is a unit test also apply here.

  • Validate against user-visible pages rather than database internals. (Sometimes, this means going to an admin page or similar to validate that a change has taken place).

Get hands-on with 1400+ tech skills courses.