LM2Alloy: Investigating LLM-Generated Formal Specifications for Automated Test Derivation in Production Software
Tasmim Rashid, Muhammad Zubair Malik
Abstract
We present an exploratory study on using Large Language Models (LLMs) to generate Alloy formal specifications from both requirements documentation and production source code, and to derive executable test cases from those specifications. We evaluate on two real open-source Python libraries: Flipper, a feature flag management system, and Cerberus, a data validation library. In both cases, the LLM produced workable Alloy specifications and executable tests without any manual correction. For Flipper, our pipeline uncovered a genuine bug that the existing test suite had missed: the library silently accepts duplicate flag names, directly contradicting its documented uniqueness requirement. A direct LLM baseline--generating tests from the same README but skipping the Alloy step--achieved 68% branch coverage yet failed to catch this bug across all three independent runs. This suggests that introducing a formal intermediate representation can surface constraint-level defects that coverage-oriented generation may miss. For Cerberus, the code-derived specification captured an implicit abstraction over sized types that the documentation-derived spec omitted, producing two additional tests. Across both libraries, code-based specifications showed lower variance in test generation (mean SD = 2.15) than documentation-based ones (mean SD = 5.0), though whether this generalises remains an open question. Index Terms--formal specifications, Alloy, large language models, automated testing, specification drift, software validation.
Create a lesson
Related papers
From Industrial Product Documentation to Automated Digital Product Passport Generation: An Experimental Study of Large Language Models
Shared title terminology · Marco Buecheler, Grant Richards, Nathan Hartman
Systematic Mapping Protocol. Generative AI-Augmented Requirements Engineering: A Systematic Mapping Study of Practices, Specifications, and Reuse in Software Development
Shared title terminology · Fernando Pinciroli
How Specification Explicitness Shapes Failure in LLM-Generated Code
Shared title terminology · Elmira Onagh, Maleknaz Nayebi
RESTOR: Automated Test Oracle Generation for RESTful APIs via Reinforcement Learning
Shared title terminology · Xun Zhou, Zhen Dong, Mingyu Ren et al.
Evaluating and Mitigating the Misguidance Effect of Buggy Code in LLM-Generated Unit Tests
Shared title terminology · Junda Zhao, Shurui Zhou, Eldan Cohen
Do Coverage and Mutation Scores of LLM-Generated Test Suites Correlate with Their Effectiveness? (Replicability Study)
Shared title terminology · Junda Zhao, Shurui Zhou, Eldan Cohen