ArticleslgStudy

computer science

Specification by example

Specification by example is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Specification by example rather than just read about it. In short: Specification by example (SBE) is a collaborative approach to defining requirements and business-oriented functional tests for software products based on capturing and illustrating requirements using realistic examples instead of abstract statements. It is applied in the context of agile software development methods, in particular behavior-driven development.

Key takeaways

  • Specification by example belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Specification by example to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Specification by example from memory before moving on to harder problems.

Reference excerpt

Specification by example (SBE) is a collaborative approach to defining requirements and business-oriented functional tests for software products based on capturing and illustrating requirements using realistic examples instead of abstract statements. It is applied in the context of agile software development methods, in particular behavior-driven development. This approach is particularly successful for managing requirements and functional tests on large-scale projects of significant domain and organisational complexity. Specification by example is also known as example-driven development, executable requirements, acceptance test-driven development (ATDD or A-TDD), Agile Acceptance Testing, test-driven requirements (TDR).

Advantages Highly abstract or novel new concepts can be difficult to understand without concrete examples. Specification by example is intended to construct an accurate understanding, and significantly reduces feedback loops in software development, leading to less rework, higher product quality, faster turnaround time for software changes and better alignment of activities of various roles involved in software development such as testers, analysts and developers.

Examples as a single source of truth A key aspect of specification by example is creating a single source of truth about required changes from all perspectives. When business analysts work on their own documents, software developers maintain their own documentation and testers maintain a separate set of functional tests, software delivery effectiveness is significantly reduced by the need to constantly coordinate and synchronise those different versions of truth. With short iterative cycles, such coordination is often required on a weekly or biweekly basis. With Specification by example, different roles participate in creating a single source of truth that captures everyone's understanding. Examples are used to provide clarity and precision, so that the same information can be used both as a specification and a business-oriented functional test. Any additional information discovered during development or delivery, such as clarification of functional gaps, missing or incomplete requirements or additional tests, is added to this single source of truth. As there is only one source of truth about the functionality, there is no need for coordination, translation and interpretation of knowledge inside the delivery cycle. When applied to required changes, a refined set of examples is effectively a specification and a business-oriented test for acceptance of software functionality. After the change is implemented, specification with examples becomes a document explaining existing functionality. As the validation of such documents is automated, when they are validated frequently, such documents are a reliable source of information on business functionality of underlying software. To distinguish between such documents and typical printed documentation, which quickly gets outdated, a complete set of specifications with examples is called Living Documentation.

Key practices Teams that apply Specification by example successfully commonly apply the following process patterns:

Deriving scope from goals Specifying collaboratively - through all-team specification workshops, smaller meetings or teleconference reviews Illustrating requirements using examples Refining specifications Automating tests based on examples Validating the underlying software frequently using the tests Evolving a documentation system from specifications with examples to support future development Software teams that apply specification by example within a Scrum framework typically spend 5%–10% of their time in refining the product backlog, including specifying collaboratively, illustrating requirements using examples and refining examples.

Example Mapping Example Mapping is a simple technique that can steer the conversation and derive Acceptance criteria in a short time. The process breaks stories into Rules and Examples documented in the form of specification by example, and is a widely used technique in the BDD sphere.

Applicability Specification by example applies to projects with sufficient organisational and domain complexity to cause problems in understanding or communicating requirements from a business domain perspective. It does not apply to purely technical problems or where the key complexity is not in understanding or communicating knowledge. There are documented usages of this approach in domains including investment banking, financial trading, insurance, airline ticket reservation, online gaming and price comparison. A similar approach is documented also in a nuclear-power plant simulation project. Tests based on shared examples fit best in the category of tests designed to support a team while delivering software from a business perspective (see Agile Testing Quadrants) - ensuring that the right product is built. They do not replace tests that look at a software system from a purely technical perspective (those that evaluate whether a product is built the right way, such as unit tests, component or technical integration tests) or tests that evaluate a product after it was developed (such as security penetration tests).

History The earliest documented usage of realistic examples as a single source of truth, requirements and automated tests, on software projects is the WyCash+ project, described by Ward Cunningham in the paper A Pattern Language of Competitive Development in 1996. The name Specification by Example was coined by Martin Fowler in 2004. Specification by Example is an evolution of the Customer Test practice of Extreme Programming proposed around 1997 and Ubiquitous Language idea from Domain-driven design from 2004, using the idea of black-box tests as requirements described by Weinberg and Gause in 1989.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Specification by example

Start with the simplest possible case. Write down what Specification by example claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Specification by example before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Specification by example ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Specification by example

In research
Specification by example appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Specification by example in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Specification by example is common in secondary-school and first-year university syllabi. It links to neighbouring topics Business analysis, Software development philosophies, Software testing, so understanding it makes those chapters shorter.
In everyday life
Look for Specification by example outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Specification by example” →

How to study Specification by example in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Specification by example means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Specification by example out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Specification by example in simple terms?

Specification by example (SBE) is a collaborative approach to defining requirements and business-oriented functional tests for software products based on capturing and illustrating requirements using realistic examples instead of abstract statements. It is applied in the context of agile software d…

Why does Specification by example matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Specification by example?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Specification by example.

Tags

  • Business analysis
  • Software development philosophies
  • Software testing

Keep exploring