Skip to main content

Automate a Spec

You have a spec that says what the system should do. SpecBinder generates the JUnit test structure and the step signatures. The remaining work is to connect those steps to the application code, set up the test data, and assert the result.

Use automate-spec to hand off that work for one .specb or .feature file in a Java project that uses JUnit 5 and Maven or Gradle. The agent looks at how nearby tests exercise the application and reuses their fixtures, clients, and step implementations where they fit.

Ask for the test you need​

Give the agent the spec path. If you have a specific test boundary in mind, name it. For example, ask “Automate CartPricing.specb against CartPricingService directly.” When the project has no existing test that shows how to exercise that behavior, the agent asks which boundary to use.

The agent finds the marker that covers the spec and reads the method signatures from the generated class. It implements missing steps in the concrete test subclass in the default abstract mode, or on the marker in concrete mode. It compiles the test sources, runs the test class, and reports the result for each scenario.

Example of a cart pricing test​

The following scenario checks the total after a discount.

CartPricing.specb (excerpt)
Scenario: a discount that divides cleanly
Given a cart holding "4" items priced "25.00"
When a discount of "10" percent is applied
Then the cart total should be "90.00"

In a test that calls the pricing service directly, the first two steps set up the cart and discount. The assertion step calls the service and compares its result with the expected total from the spec. This is the sort of step implementation the agent writes when it follows the project's unit test pattern. Runnable cart pricing example

CartPricingUnitTest.java (excerpt)
@Override
public void theCartTotalShouldBe$p1(String expected) {
assertEquals(new BigDecimal(expected), pricing.total(quantity, unitPrice, discount));
}

That method lives in the handwritten test that extends CartPricingScenarios. SpecBinder supplies the generated scenario and signature. The step implementation supplies the call to the application and the assertion.

Read the test result​

The agent fixes test wiring errors it introduced and reruns the test. If the spec expects a behavior the application doesn't provide yet, the agent reports the expected and actual results. A step that needs missing application code fails with a message naming what it needs. That gives you a concrete starting point for the next implementation change.

For the basics of marker classes, generated tests, and handwritten steps, see Getting Started.