Back to all posts
• 7 min read

Fumapps Testing Methodology: Sociable BDD with Internal DSLs

How we combine Sociable Unit Testing, Behavior-Driven Development (BDD), and Internal DSLs into a cohesive testing approach that ensures refactoring safety and high readability.

When testing applications with rich state or presentation logic, it is surprisingly easy to end up with a test suite that nobody likes maintaining. If you rely too heavily on End-to-End (E2E) tests that drive the rendered Graphical User Interface (GUI), your test runs become slow, flaky, and fragile whenever layouts change. If you swing to the opposite extreme and write solitary, mock-heavy unit tests for every single class, your tests ossify the internal structure of your code and break whenever you refactor a private helper or split a class in two.

Architectural patterns such as Model-View-ViewModel (MVVM) and Clean Architecture give us a natural middle ground by separating presentation and domain logic from heavy GUI frameworks and databases. That lets us run fast tests directly against a ViewModel or a component facade without spinning up a GUI toolkit.

Even with a clean architecture, however, writing tests in a General-Purpose Language (GPL) such as Java, C++, or C# quickly runs into a boilerplate versus logic problem. Setting up test preconditions, triggering commands, and verifying complex state (such as a multi-column table, a two-dimensional grid, or the enabled states of several toolbar buttons) often buries the actual test intent under dozens of lines of low-level getters and index-based assertions.

To keep our test suites both fast and readable, we combine four practical techniques into what we call Sociable BDD with Internal DSLs: testing real collaborating objects behind a stable facade (Sociable Unit Testing), structuring scenarios around observable behavior with Behavior-Driven Development (BDD), hiding setup plumbing behind Composed Methods, and verifying complex structures with string-based internal Domain-Specific Languages (DSLs).


Testing Behavior Behind a Stable Facade

In classic solitary unit testing, every collaborator of a class under test is replaced with a mock or stub. While that isolates failures to a single class, it couples the test directly to internal communication protocols. Rename an internal service method or move responsibility between two internal classes, and dozens of tests fail even though the externally observable behavior did not change at all.

With Sociable Unit Testing, we treat a cohesive cluster of collaborating classes as a single unit and test it strictly through its stable facade, such as a ViewModel or a domain controller. Behind that entry point, the collaborators are real objects working together. Depending on the architectural layer we want to cover, we either test the view logic together with the real business logic (mocking only external boundaries such as persistence or network services), or we test a complex view-logic cluster against a mocked business boundary. In both cases, the internal structure behind the facade remains a black box to the test.

Once we test at the facade level, the next challenge is keeping the test code itself focused on domain behavior rather than technical plumbing. Suppose we want to verify that loading two objects into a C++ ViewModel populates a table with two formatted rows. If we write that test using raw collection accessors, we end up with repetitive index chains like EXPECT_EQ(rows[0].Id(), "0x0001"), EXPECT_EQ(rows[0].Name(), "ObjA"), and so on for every single cell.

Compare that verbosity with how we actually write such tests in C++:

TEST_F(ObjectTest, Given2Objects_WhenLoadView_ThenShow2Rows) {
    WithObjects(Object(0x01, "ObjA", "Integer"),
                Object(0x02, "ObjB", "String"));
    LoadView();
    AssertTable("0x0001|ObjA|Integer|\n"
                "0x0002|ObjB| String|\n");
}

Here, the method name follows the Given-When-Then convention from BDD to state the scenario intent upfront. The helper methods WithObjects and LoadView apply the Composed Method pattern so the reader is not distracted by how mock repositories are wired or how the ViewModel is instantiated. Finally, AssertTable uses a small string-based internal DSL to verify the entire table structure in one glanceable block.


Practical Case Study: The Java Hamster Simulator

To see how this plays out on a richer state space, let us look at a test case from the open-source Java Hamster Simulator, developed at the Institute of Software Engineering at the University of Stuttgart for teaching programming.

In the simulator, a hamster moves through a two-dimensional grid territory containing walls and grains, while a toolbar of playback buttons (play, pause, undo, redo) changes its sensitivity (enabled or disabled state) depending on the simulation state. Writing a test that loads a territory, moves the hamster one step forward, and checks every tile of the grid plus all four toolbar buttons would normally take dozens of assertEquals and assertTrue calls.

Using composed helper methods and two lightweight string DSLs, the entire scenario fits into a few expressive lines of Java:

@Test 
public void testHamsterView() throws IOException {
    // Given
    loadTerritory("example01.ter");

    // When
    moveHamster();

    // Then
    assertTerritory(
        "|####|####|####|\n" +
        "|    |>   | 1* |\n" +
        "|####|####|####|\n"
    );
    assertButtons("/play/ [pause] /undo/ /redo/");
}

When you read testHamsterView(), you do not see internal controllers, movement engines, or ViewModel property getters. Every line operates at the same behavioral level of abstraction:

  1. Preconditions (Given): loadTerritory("example01.ter") initializes the real simulator components with a predefined territory file.
  2. Action (When): moveHamster() triggers the movement command on the facade, which updates the underlying territory model and recalculates the playback button states across all collaborating classes.
  3. Visual State Verification (Then): assertTerritory(...) parses a multi-line string representation of the two-dimensional grid, where #### denotes a wall tile, > shows the hamster facing east on the middle tile, and 1* represents a single grain lying ahead. Right below it, assertButtons(...) checks the toolbar state in one line: slashes (/play/, /undo/, /redo/) assert that a button is enabled, while square brackets ([pause]) assert that a button is disabled.

Where This Approach Shines and Where It Hits Limits

Using sociable BDD tests with string-based internal DSLs across both C++ and Java projects has taught us where this pattern pays off and where its trade-offs lie.

Why We Like It in Day-to-Day Engineering

The biggest practical win is refactoring safety. Because tests only talk to the facade through composed helper methods and assert observable output state, we can restructure internal classes, extract new collaborators, or change how state is stored without touching the test suite.

The second win is failure diagnostics through text diffs. When a loop of twenty assertEquals calls fails on row 1, column 2, reconstructing what the whole table or grid actually looks like takes mental effort or a debugger session. When assertTerritory or AssertTable fails, the unit test runner prints a side-by-side string diff of the expected versus actual grid. You see immediately if the hamster turned the wrong way, if a row was sorted into the wrong position, or if the undo button stayed disabled.

The third win shows up in agentic workflows. As Matteo Vaccari explains in Tests as data, when Artificial Intelligence (AI) coding agents write the production code, human developers step into the role of customers, making black-box customer tests the primary contract between humans and AI. Representing expected state as compact tables and visual text strings (AssertTable, assertTerritory, assertButtons) rather than imperative assertion code follows this tests as data mindset. When you take the further step of moving those tabular cases or text scenarios into dedicated data files interpreted by a small test runner, you can also guard the behavioral specification against silent agent edits during refactoring (a key theme we explore in The Importance of Tests in Agentic Engineering).

The Honest Trade-Offs

At the same time, this style of testing is not free, and we have run into clear limitations when scaling it across large applications:

  • Building and maintaining custom DSL helpers takes effort: Someone has to write the string parsers and formatting helpers behind assertTerritory, assertButtons, and AssertTable. As the application grows, maintaining that custom test infrastructure becomes an ongoing engineering task of its own.
  • Coarser defect localization: Because a sociable test exercises several real classes together, a red test tells you what behavior broke, not which internal class caused it. If testHamsterView fails, the bug might sit in the territory loader, the movement logic, or the button state mapping. In practice, we gladly trade a minute of pinpointing for a test suite that survives refactorings, but the trade-off is real.
  • Hidden context in external fixtures: Loading state from external files such as example01.ter (often called the Mystery Guest smell) keeps the test short, but forces the reader to open another file to see where the hamster started before moveHamster() was called. For smaller scenarios, inline setup builders like WithObjects(...) make the cause-and-effect relationship much clearer.
  • No Integrated Development Environment (IDE) support inside strings: To the Java or C++ compiler, "/play/ [pause] /undo/ /redo/" is just an opaque string literal. You get no syntax highlighting, no autocompletion when writing assertions, and no automated rename refactoring if a button or column changes. Furthermore, plain text strings quickly become awkward when you want to assert richer presentation details such as icons, row colors, tooltips, or checkboxes.

Conclusion

Combining Sociable Unit Testing, BDD scenario structure, Composed Methods, and string-based internal DSLs is a pragmatic way to make unit and integration tests both readable and resilient to refactoring. Even without external tooling, wrapping your test setup in domain-focused helper methods and asserting complex state through compact visual strings eliminates most of the noisy boilerplate that plagues traditional test suites.