Source-linked AI summary

TOGA: A Neural Method for Test Oracle Generation

Elizabeth Dinella, Gabriel Ryan, Todd Mytkowicz, Shuvendu K. Lahiri

arXiv:2109.09262v2cs.SE

TL;DR

Functional test-oracle generation must capture developer intent rather than merely reproduce implemented behavior, despite ambiguous or missing documentation. TOGA uses a transformer-based approach that infers exceptional and assertion oracles by ranking constrained candidates. It improves oracle-inference accuracy and finds real-world Java bugs, including bugs missed by other evaluated automated methods.

  • Problem

    Automated tools lack definitive knowledge of developer intent, while functional oracle generation must handle ambiguous or missing documentation and missing implementations.

  • Method

    TOGA uses pretrained transformers to rank grammar- and type-constrained candidates for exceptional and assertion oracles, without relying on the unit’s implementation.

  • Results

    TOGA improves oracle-inference accuracy by 33%, achieves 96% accuracy on a held-out dataset, and finds 57 real-world bugs, including 30 missed by other evaluated methods.

  • Takeaways & Limitations

    TOGA provides an end-to-end neural test-oracle generation technique that integrates with EvoSuite and supports future work through two released datasets.

  • Takeaways & Limitations

    TOGA can generate only grammar-expressible oracles whose values appear in its vocabulary; among incorrect bug-finding assertions, 54% lacked vocabulary values and 8.5% exceeded the grammar.

Abstract

from arXiv · show

Testing is widely recognized as an important stage of the software development lifecycle. Effective software testing can provide benefits such as bug finding, preventing regressions, and documentation. In terms of documentation, unit tests express a unit's intended functionality, as conceived by the developer. A test oracle, typically expressed as an condition, documents the intended behavior of a unit under a given test prefix. Synthesizing a functional test oracle is a challenging problem, as it must capture the intended functionality rather than the implemented functionality. In this paper, we propose TOGA (a neural method for Test Oracle GenerAtion), a unified transformer-based neural approach to infer both exceptional and assertion test oracles based on the context of the focal method. Our approach can handle units with ambiguous or missing documentation, and even units with a missing implementation. We evaluate our approach on both oracle inference accuracy and functional bug-finding. Our technique improves accuracy by 33\% over existing oracle inference approaches, achieving 96\% overall accuracy on a held out test dataset. Furthermore, we show that when integrated with a automated test generation tool (EvoSuite), our approach finds 57 real world bugs in large-scale Java programs, including 30 bugs that are not found by any other automated testing method in our evaluation.

1 INTRODUCTION

TOGA targets functional test-oracle generation, where automated tools lack definitive knowledge of developer intent and existing methods struggle with flexible or missing documentation. It combines constrained oracle candidates with transformer ranking and reports improved inference accuracy and real-world bug finding.

  • Unit tests document intended functionality, detect mismatches between intended and implemented behavior, and help prevent regressions.
  • Automated test-generation tools typically use crashes or undesirable exceptions as oracles, leaving violations of intended functionality insufficiently tested.
  • Specification-mining methods rely on restricted documentation structures and handcrafted rules, which fail when real-world documentation is flexible or absent.
  • TOGA ranks a small set of grammar- and type-constrained exceptional or assertion oracles using pretrained transformers.
  • 33% accuracy improvement and 96% accuracy on a held-out dataset were reported, alongside 57 real-world bugs, including 30 missed by other evaluated methods.

2 RELATED WORK

Prior automated, specification-mining, and neural approaches each have limitations for finding functional bugs: they may assume current behavior is correct, depend on rigid documentation, or generate inaccurate assertions.

  • Automated Test Generation Tools: Automated test-generation tools construct prefixes but generally rely on crashes, exception heuristics, or regression behavior rather than intended functionality.
  • Automated Test Generation Tools: Regression oracles can encode buggy current behavior, while safety oracles can pass tests on buggy implementations and flag correct exceptions as failures.
  • Specification Mining Methods: Specification-mining methods infer oracles from docstring patterns, but real-world comments often lack the precise structure those methods require.
  • Neural Methods: Neural methods handle flexible documentation better than fixed-pattern approaches, yet generative models struggle with the large space of possible assertions.
  • Neural Methods: Transformer-based neural methods improve inference accuracy over earlier recurrent models, but struggle to find real-world Java bugs when paired with test-prefix generation.

3 STRUCTURE OF AN ORACLE

TOGA models test oracles as either expected exceptions or return-value assertions. A compact grammar captures common oracle structures, while type constraints prune candidates before neural ranking.

  • Oracle Taxonomy: The taxonomy was derived from observations of almost 200K developer-written tests and manually inspected samples.
  • Oracle Taxonomy: Expected exception oracles verify that invalid test-prefix usage raises an exception.
  • Oracle Taxonomy: Assertion oracles check return behavior using Boolean, nullness, or equality assertions and related assert* constructs.
  • Oracle Grammar: The grammar captures 82% of a large developer-written test dataset while intentionally restricting the language to common, semantically equivalent oracle forms.
  • Oracle Grammar: The oracle grammar represents a test as a prefix followed by either an exceptional oracle or an assertion oracle.
  • Candidate Ranking: TOGA uses type constraints to prune grammar-generated candidates and neural models to rank the remaining possible test oracles.

4 TOGA: NEURAL TEST ORACLE GENERATION

TOGA infers exceptional and assertion oracles from a test prefix and unit context, without requiring the unit implementation. It combines transformer-based classification and constrained assertion ranking to produce functional test oracles.

  • TOGA infers both exceptional and assertion oracles from a test prefix and unit context, even when documentation or implementation is absent.The unit context may contain method signatures and docstrings, but need not include the implementation.
  • The Exceptional Oracle Classifier uses a fine-tuned pretrained transformer to decide whether the test prefix should raise an exception.An inferred exceptional oracle can directly produce a complete expected-exception test.
  • The Assertion Oracle Ranker treats assertion inference as ranking a small set of common candidate oracles constrained by a grammar and type information.This design restricts the candidate space and enforces syntactic and type correctness.
  • The Assertion Oracle Ranker fine-tunes CodeBERT on test prefixes, unit contexts, candidate assertions, and binary labels indicating whether candidates reflect developer intent.At inference, the highest-confidence assertion is selected from the generated candidate set.
  • TOGA integrates with EvoSuite by stripping generated oracles from coverage-guided tests, then inferring new oracles from the resulting prefixes.The integration assumes EvoSuite’s standardized test format to identify assertion-relevant variables.

5 EVALUATION

The evaluation measures TOGA’s oracle coverage, inference accuracy, and bug-finding performance. TOGA supports many developer assertions, improves assertion and exceptional-oracle inference, and finds bugs that other evaluated methods miss, while test-prefix generation remains a major constraint.

  • RQ1: Oracle Grammar: 82% of developer-written assertions in ATLAS are expressible in TOGA’s grammar, while 74% of sampled non-matching assertions appear symbolically equivalent to expressible assertions.The grammar covers 154,523 of 188,157 assertions; many excluded assertions use unsupported assertion methods.
  • RQ2: Oracle Inference Accuracy: 96% accuracy on the in-vocab assertion set and 69% overall accuracy exceed the seq2seq baseline’s 63% in-vocab accuracy.The overall result is an 11% relative improvement over the seq2seq model.
  • RQ2: Oracle Inference Accuracy: Increasing the global dictionary size slightly lowers candidate-set accuracy but improves overall accuracy by generating correct candidates for more samples.Using only the local dictionary supports correct candidates for approximately 50% of test samples.
  • RQ3: Bug Detection: 57 bugs were found in Defects4J, including 30 not found by any other evaluated method.Randoop found 20 bugs with a much higher false-positive rate, while the seq2seq model found 6 and JDoctor found 1.
  • RQ3: Bug Detection: TOGA found 44 bugs involving exceptional behavior, including 5 expected-exception failures that no other evaluated method detected.Its exception model correctly identified 39 of 45 unexpected exceptions.
  • RQ3: Bug Detection: TOGA’s bug-finding results were limited mainly by unreachable test prefixes and incorrect oracle generation.It missed 715 Defects4J bugs because EvoSuite did not reach the relevant prefixes and 63 because TOGA generated incorrect oracles.

6 LIMITATIONS

TOGA trades unrestricted oracle expression for accurate prediction within a restricted grammar and vocabulary. Its coverage is limited by unseen assertion values, unsupported syntax, training distribution, and assumptions about EvoSuite prefixes.

  • Grammar and Vocabulary: TOGA can generate only oracles expressible by its grammar and containing values from its vocabulary.This restriction is an explicit tradeoff for more accurate prediction within the supported set.
  • Grammar and Vocabulary: 54% of incorrect bug-finding assertions used values absent from the vocabulary, while 8.5% could not be expressed by the grammar.These figures come from manual analysis of TOGA predictions in the bug-finding evaluation.
  • Out of distribution training: TOGA depends on developer-written unit-test datasets for training and vocabulary learning, whereas the RQ3 test set uses out-of-distribution EvoSuite samples.The authors suggest training on EvoSuite-generated data as a future direction.
  • Dependencies on EvoSuite: TOGA assumes EvoSuite-generated prefixes provide a suitable assertion variable, so integrating another test generator may require mutation analysis to select variables.The authors identify PIT as one possible tool for this integration.

7 CONCLUSION

The paper presents TOGA, a two-step transformer technique that infers exception and assertion oracles from test prefixes and unit context, including cases without implementations or docstrings. Integrated with EvoSuite, it finds 57 real-world bugs and outperforms existing oracle-inference techniques.

  • Conclusion: TOGA infers exception and assertion test oracles from a test prefix and unit context using a two-step transformer architecture.The approach can generate oracles for units without implementations or docstrings.
  • Conclusion: TOGA ranks a small set of likely candidate assertions rather than generating assertions token by token.This design improves upon generative neural assertion-oracle inference techniques.
  • Conclusion: 57 real-world bugs were found when TOGA was integrated with EvoSuite, outperforming existing test-oracle inference techniques.The paper also presents two datasets for future work on neural exception and assertion test-oracle inference.
Loading 2109.09262v2…