Boilerplate Code

Boilerplate Code image
Boilerplate code, often just called boilerplate, is repetitive, standard code that has to be written for a program or framework to work but contains little logic of its own. In test automation, boilerplate includes initial class structures, setup and teardown methods, imports, configuration and the simplest unit tests.

Why it matters: Boilerplate takes time without adding much thinking. Setting up the initial classes and architecture of a new automation project can take days, even for skilled programmers. That time and tedium is one reason teams look for ways to generate or reduce boilerplate, so effort goes into the tests that matter.

In practice: Teams reduce boilerplate with project templates, code generators, base classes, shared libraries and IDE snippets. AI coding assistants are increasingly used too: you describe the task in plain language and the assistant drafts the initial code in seconds, which the tester then reviews and adapts. This helps overcome the fear of a blank page, but the output still needs checking.

Examples:

  • Creating page object classes with the same constructor, locators and wait logic for every page in a web application.
  • Writing a client class with create, retrieve, update and delete methods for each API endpoint under test.
  • Writing basic unit tests that check getters, setters and default values for a simple class.

Common pitfalls:

  • Accepting generated boilerplate without review, so outdated library calls or poor structure become the foundation of the whole framework.
  • Copying and pasting the same boilerplate across many files instead of moving it into a shared base class or helper, which makes later changes slow and error prone.

Is boilerplate code bad? Not in itself. Some boilerplate is unavoidable and keeps code predictable. It becomes a problem when it is duplicated widely, hides the important logic, or takes up time that would be better spent on designing meaningful tests.
Explore MoT
Test Forward 2027 ยท Software Quality in the age of AI image
Tue, 19 Jan 2027
Test Forward is one afternoon at Station F with the QA and engineering people closing that gap in their own teams.
MoT Advanced Certificate in Test Automation image
Ascend to leadership roles by mastering strategic skills in automation strategy creation, planning and execution
This Week in Quality image
Debrief the week in Quality via a community radio show hosted by Simon Tomes and members of the community
Subscribe to our newsletter