Automated Unit Test Improvement Using LLMs for Android Applications

meta · Tech · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Android test improvement

Meta needed to improve unit-test coverage for large Android Kotlin applications by generating additional tests that cover neglected edge cases while filtering out unreliable or non-buildable LLM output.

Constraints:

Architecture

Meta built TestGen-LLM around an Assured Offline LLM-Based Software Engineering workflow. The tool generates additional Kotlin unit tests for existing Android test suites, then subjects candidate tests to a filtration process that checks buildability, reliability, flakiness resistance, and novel coverage contribution before recommending them to engineers. The system was evaluated and deployed in test-a-thons for Instagram and Facebook.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  existing-test-suite[Existing test suite] --> testgen-llm-generator[TestGen LLM generator]
  testgen-llm-generator --> assured-filtration-pipeline[Assured filtration pipeline]
  assured-filtration-pipeline --> engineer-recommendation-surface[Engineer recommendation surface]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Existing test suite Provides the baseline Android Kotlin tests to improve. TestGen LLM generator
TestGen LLM generator Generates additional candidate unit tests for neglected edge cases. Existing test suite, Assured filtration pipeline
Assured filtration pipeline Rejects generated tests that fail buildability, reliability, flakiness, or coverage criteria. TestGen LLM generator, Engineer recommendation surface
Engineer recommendation surface Presents filtered test improvements to Meta engineers for production use. Assured filtration pipeline

Data flow

Existing Android unit tests and target classes feed TestGen-LLM. The LLM proposes additional edge-case tests, the assured offline pipeline filters candidates through buildability, reliability, flakiness, and coverage checks, and only candidates that strengthen the test suite become engineer-facing recommendations.

3 supporting quotes
“TestGen-LLM, an innovative tool developed by Meta Platforms Inc., which leverages LLMs to generate additional test cases for existing unit tests”article, stated
“rigorous filtration process, which discards any candidate test cases that do not meet stringent criteria such as buildability, reliability, resistance to flakiness”article, stated
“A key feature of the tool is its rigorous filtration process, which discards any candidate test cases that do not meet stringent criteria such as buildability, reliability, resistance to flakiness, and contribution to novel code coverage.”article, stated

Why this architecture

The architecture treats generation as only the first step. The key design is the assured offline filter: generated tests are useful only if they compile, behave reliably, avoid flakiness, and add coverage. This allows LLM output to be used in production engineering workflows without asking engineers to manually triage every raw candidate.

3 supporting quotes
“TestGen-LLM exemplifies a methodology known as Assured Offline LLM-Based Software Engineering (Assured Offline LLMSE).”article, stated
“This approach ensures that the generated test cases not only adhere to but also enhance the quality of the original test suite.”article, stated
“This process ensures that the test cases recommended by TestGen-LLM effectively strengthen the robustness of the test suite.”article, stated

Models used: large language model for test generation · ensemble learning mentioned as an innovative aspect

Scale

Alternatives considered (roads not taken)

Manual test coverage improvement

Rejected because: Manual coverage improvement requires significant developer effort across large codebases.

“The paper "Automated Unit Test Improvement using LLMs at Meta" explores the use of LLMs in the automation of unit test enhancement, specifically targeting Android applications written in Kotlin.”article, stated

Recommend raw LLM-generated tests

Rejected because: Meta filtered generated tests for buildability, reliability, flakiness resistance, and novel coverage before recommendation.

“A key feature of the tool is its rigorous filtration process, which discards any candidate test cases that do not meet stringent criteria such as buildability, reliability, resistance to flakiness, and contribution to novel code coverage.”article, stated

Use generation only for evaluation

Rejected because: The system was designed for both evaluation and deployment.

“The system architecture of TestGen-LLM involves a dynamic dual-use approach, focusing on both evaluation and deployment.”article, stated

Patterns

eval-driven-development (evaluation)

Generated tests are accepted only after objective checks for buildability, reliability, flakiness resistance, and coverage improvement.

“buildability, reliability, resistance to flakiness, and contribution to novel code coverage”article, stated

guardrails-io-filtering (reliability)

The filtration layer discards candidate test cases that fail quality criteria before they reach engineers.

“rigorous filtration process, which discards any candidate test cases that do not meet stringent criteria”article, stated

batch-offline-processing (operations)

The workflow is explicitly framed as assured offline LLM-based software engineering rather than an interactive assistant.

“Assured Offline LLM-Based Software Engineering (Assured Offline LLMSE)”article, stated

human-in-the-loop-gate (workflow)

Filtered test recommendations are accepted by Meta engineers before production use.

“most recommendations being positively accepted by Meta's software engineers for production.”article, stated

Tradeoffs

Use an assured offline workflow

Chose filtered, validated recommendations over online raw generation.

Rationale: Offline assurance gives the organization time to validate generated tests before exposing them as production recommendations.

“Assured Offline LLM-Based Software Engineering (Assured Offline LLMSE)”article, stated
“This process ensures that the test cases recommended by TestGen-LLM effectively strengthen the robustness of the test suite.”article, stated

Target improvement of existing tests

Chose additional test cases for existing unit tests over generating entire test suites from scratch.

Rationale: The source frames the tool around neglected edge cases in existing suites, which narrows validation and engineer review.

“generate additional test cases for existing unit tests, aiming to improve code coverage by addressing neglected edge cases.”article, stated

Gotchas (what bit them)

LLM-generated tests can fail build or reliability requirements.

Root cause: Raw generated tests may not satisfy industrial codebase constraints.

Resolution: Meta discards candidates that fail buildability, reliability, flakiness, or coverage checks.

“discards any candidate test cases that do not meet stringent criteria such as buildability, reliability, resistance to flakiness”article, stated

Improving coverage is not enough if tests duplicate existing coverage.

Root cause: Generated tests need to contribute novel code coverage rather than simply adding more lines.

Resolution: The filtration process requires contribution to novel code coverage.

“contribution to novel code coverage”article, stated

Evaluation

Meta evaluated TestGen-LLM through deployment in test-a-thons and quantitative measurement of classes enhanced and engineer acceptance.

Metrics: classes enhanced · coverage improvement · engineer recommendation acceptance · buildability · reliability · flakiness resistance

“During evaluations, particularly within Instagram's Reels and Stories, a significant portion of the test cases generated by TestGen-LLM were found to be reliable”article, stated
“Quantitative results from the study indicate that TestGen-LLM was able to enhance 10% of the classes it was applied to”article, stated

Outcomes

The available article gives percentage and deployment context, but not absolute project or test counts.

“enhance 10% of the classes it was applied to, with most recommendations being positively accepted”article, stated
“TestGen-LLM's deployment at Meta, highlighting its application in test-a-thons for platforms such as Instagram and Facebook.”article, stated