https://www.boundaryml.com logo
🟡 Reusable Assertion Templates in Test Cases
# questions
i
I'm writing multiple tests that need to verify the same conditions, and I find myself copying the same
@@assert
expressions repeatedly. For example:
Copy code
baml
@@assert(should_call_get_allowed_countries_tool, {{ this.tool_calls|selectattr('name', 'equalto', 'get_allowed_countries')|list|length > 0 }})
This exact assertion appears in many of my test cases. It would be great to have a way to define reusable assertion templates that can be referenced by name across tests. Something like:
Copy code
baml
// Define once
assertion should_call_tool(tool_name: string) {{ 
  this.tool_calls|selectattr('name', 'equalto', tool_name)|list|length > 0 
}}

// Reuse in tests
test MyTest1 {
  functions [MyFunction]
  args { ... }
  @@assert(should_call_tool("get_allowed_countries"))
}

test MyTest2 {
  functions [MyFunction]
  args { ... }
  @@assert(should_call_tool("get_allowed_countries"))
}
This would reduce duplication and make tests more maintainable. Is this something that's on the roadmap, or is there an existing pattern I'm missing?
Also I'd suggest having in the test cases a "describe" field. So when I run a test in the extension I can see something like: "it should trigger a tool call ..." This will make it easier to understand what we expect from the test, instead of having the CapitalCase test name