On the Flakiness of LLM-Generated Tests for Industrial and Open-Source Database Management Systems

Alexander Berndt, Thomas Bach, Fatma Özcan, Marcus Kessel, Sebastian Baltes · DOI

Abstract

Flaky tests are a common problem in software testing. They produce inconsistent results when executed multiple times on the same code, invalidating the assumption that a test failure indicates a software defect. Recent work on LLM-based test generation has identified flakiness as a potential problem with generated tests. However, its prevalence and underlying causes are unclear. We examined the flakiness of LLM-generated tests in the context of four relational database management systems: SAP HANA, DuckDB, MySQL, and SQLite. We amplified test suites with two LLMs, GPT-4o and Mistral-Large-Instruct-2407, to assess the flakiness of the generated test cases. Our results suggest that generated tests have a slightly higher proportion of flaky tests compared to existing tests. Based on a manual inspection, we found that the most common root cause of flakiness was the reliance of a test on a certain order that is not guaranteed ("unordered collection"), which was present in 72 of 115 flaky tests (63%). Furthermore, both LLMs transferred the flakiness from the existing tests to the newly generated tests via the provided prompt context. Our experiments suggest that flakiness transfer is more prevalent in closed-source systems such as SAP HANA than in open-source systems. Our study informs developers on what types of flakiness to expect from LLM-generated tests. It also highlights the importance of providing LLMs with tailored context when employing LLMs for test generation.

1. Introduction

Automated test generation using Large Language Models (LLMs) is gaining significant traction because LLMs produce highly readable, human-like code compared to traditional search-based tools. However, industrial software testing is plagued by flaky tests: tests that non-deterministically pass or fail on the exact same code. Flaky tests undermine developer trust and consume expensive debugging resources, as failures do not necessarily indicate a software defect. While previous research noted that LLMs can generate flaky tests, the exact prevalence, root causes, and mechanisms behind this phenomenon in complex domains like Database Management Systems (DBMS) remained unclear.

2. Methodology

The authors employed an LLM-based test amplification approach, taking existing test files and prompting two models—GPT-4o and Mistral-Large-Instruct-2407—to write extended versions covering additional corner cases.

Workflow of the LLM-based test generation and flakiness evaluation process.

As shown in the workflow above, generated tests were parsed, patched into original files, compiled, and executed 30 times within isolated Docker containers. Any test exhibiting both passes and failures across these runs was flagged as flaky. Following identification, the authors performed a manual root cause analysis and conducted a "flakiness transfer" experiment by injecting a 50/50 flaky assertion into existing tests to see if LLMs would propagate this behavior into new code.

3. Experimental Setup and Datasets

The study evaluated native C++ unit tests and SQL system tests across four relational databases: SAP HANA (a closed-source industrial database), MySQL (open-source C++ tests), and SQLite and DuckDB (open-source SQL tests). Over 5,000 test files were processed to establish a comprehensive baseline for comparison.

4. Results and Analysis

The study identified a total of 115 flaky tests across the generated suites (96 SQL and 16 C++). The prevalence of flakiness in LLM-generated code was found to be slightly higher than in the human-written baseline.

Baseline flakiness metrics for the existing human-written test suites across the four evaluated systems.

A primary finding was the "Unordered Collection" trap: 63% of flaky tests (72 out of 115) were caused by SQL tests expecting a specific output order without an ORDER BY clause. LLMs often miss these underlying execution semantics despite understanding syntax. Additionally, the "flakiness transfer" experiment revealed that LLMs are highly susceptible to shortcut learning. When a flaky assertion was injected into the prompt, GPT-4o transferred it to 70% of SAP HANA tests but only 41% of MySQL tests. This suggests a "closed-source penalty" where models over-rely on prompt context when they lack pre-training knowledge of the codebase.

5. Discussion and Conclusion

The results highlight that LLMs are prone to "fashion following," where bad patterns or non-deterministic logic in the prompt are blindly copied into new tests. This is particularly critical for SQL system tests where the schema and execution rules live outside the immediate test file. Future work should focus on developing automated ways to provide LLMs with tailored, system-wide context to mitigate these issues. While the 30-run execution limit might miss extremely rare flaky tests, this study provides a critical baseline for understanding the non-functional reliability of LLM-generated code in industrial settings.

Summary updated

Abstract

Flaky tests are a common problem in software testing. They produce inconsistent results when executed multiple times on the same code, invalidating the assumption that a test failure indicates a software defect. Recent work on LLM-based test generation has identified flakiness as a potential problem with generated tests. However, its prevalence and underlying causes are unclear. We examined the flakiness of LLM-generated tests in the context of four relational database management systems: SAP HANA, DuckDB, MySQL, and SQLite. We amplified test suites with two LLMs, GPT-4o and Mistral-Large-Instruct-2407, to assess the flakiness of the generated test cases. Our results suggest that generated tests have a slightly higher proportion of flaky tests compared to existing tests. Based on a manual inspection, we found that the most common root cause of flakiness was the reliance of a test on a certain order that is not guaranteed ("unordered collection"), which was present in 72 of 115 flaky tests (63%). Furthermore, both LLMs transferred the flakiness from the existing tests to the newly generated tests via the provided prompt context. Our experiments suggest that flakiness transfer is more prevalent in closed-source systems such as SAP HANA than in open-source systems. Our study informs developers on what types of flakiness to expect from LLM-generated tests. It also highlights the importance of providing LLMs with tailored context when employing LLMs for test generation.
BibTeX
@inproceedings{berndt2026flakiness,
  author = {Alexander Berndt and Thomas Bach and Fatma Özcan and Marcus Kessel and Sebastian Baltes},
  title = {{On the Flakiness of LLM-Generated Tests for Industrial and Open-Source Database Management Systems}},
  booktitle = {SEIP@ICSE},
  year = {2026},
  doi = {10.1145/3786583.3786919},
}
Figure