Tools

Writing executable specifications with Bobcat in C#

Critter Stack's new Bobcat 1.0 turns ordinary C# tests into readable executable specifications. The author starts from an existing xUnit test, adds step helpers, then covers decision tables and set verification for collections. It is a practical walkthrough for .NET teams who want reviewable tests without a Gherkin layer.

Published
Reading time
10 min read
agent run #15
agent run #15
Go to original jeremydmiller.com

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Key points

  • Adding [BobcatFeature] to an existing xUnit test is enough; xUnit v3, TUnit, NUnit and MSTest (3.10+) are supported
  • Step helpers must be internal, not private, because the generated interceptor is an extension method
  • SpecAssert.Check records mismatches and lets the scenario continue; the adapter fails the test once at the end
  • TableRunner.Run calls a row method per table row, and out parameters act as extra output columns
  • Set verification with keyColumns marks rows as EXTRA, MISSING, FAIL or ORDER
  • xUnit v2 has no adapter; use the shipped Bobcat.* runner adapter, since hand-rolled ones may never set the verdict

Bobcat 1.0 is out, a tool from the Critter Stack team for writing executable specifications. It descends from Storyteller and, before that, FitNesse, but drops the separate Gherkin files. A specification is a C# test, so developers keep authoring it while domain experts review the rendered steps.

The article walks through one overdraft rule. An existing xUnit test becomes a specification by adding a feature attribute and comments, and helper methods marked with Given, When and Then attributes record each step. Boundary cases move into a pipe or markdown table that a row method runs, and collection checks use set verification with EXTRA, MISSING and ORDER verdicts. Helpers must be internal, and SpecAssert.Check records mismatches instead of stopping the run.

Real-world use

  • Testing business rules with many boundary cases, such as account balances, pricing or tax rules, as decision tables
  • Sharing rules with product and domain reviewers through rendered steps instead of Gherkin files
  • Checking that a transaction history contains exactly the expected rows, with EXTRA and MISSING verdicts

Why it matters

You can turn existing xUnit tests into reviewable specifications with little change to their logic. Table and set verdicts show exactly which row or history entry disagrees, which helps in data-heavy test suites.

This summary was generated by the agent from the original post on Jeremy D. Miller (The Shade Tree Developer). The full text and all rights belong to its author and publisher. Go to original

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message