<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Adopting Program Synthesis for Test Amplification</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Mehrdad Abdi</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Henrique Rocha</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Serge Demeyer Universiteit Antwerpen and Flanders Make België</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Universiteit Antwerpen België</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>Program synthesis is the task of enabling a computer system to automatically write program code based on user intent. Test amplification on the other hand is an emerging research area, where the goal is to generate new test cases from manually written ones. From this perspective, test amplification is awfully similar to program synthesis. Therefore, in this short paper, we explore the benefits of using program synthesis for test amplification.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>Index terms— test amplification, program
synthesis, test generation, big code
Software is used in most aspects of modern human life
and the importance of reliability in software is
undeniable. Software testing is the de facto technique for
reducing the risk of defects, thus making software
systems more reliable.</p>
      <p>
        Test cases can be generated automatically by tools
or can be written manually by developers.
Autogenerated test cases provide reasonable test coverage
but in most cases are hard to maintain because
generators fail to generate human understandable test cases.
On the other hand, manually written test cases cover
most of the main functionality of the program but may
suffer from low coverage. Test amplification serves as
a kind of middle ground [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. Test amplifiers exploit
the knowledge of the manually written tests in order
to enhance existing test cases to increase coverage.
      </p>
      <p>
        In an earlier paper we demonstrated the feasibility
of test amplification for Pharo Smalltalk, a
dynamically typed programming language [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Nevertheless,
we observed some areas for improvement, especially
with regard to the readability of the amplified test
cases. Therefore, in this paper, we explore the
benefits of using program synthesis for test amplification.
      </p>
      <p>The remainder of this paper is organized as follows.
In section 2, we describe the Small-Amp tool
prototype, discussing some of its shortcomings. In section 3
we describe promising ideas from program synthesis as
a potential way for addressing these shortcomings. In
section 4 we suggest possible benefits of program
synthesis for test amplification. Finally in 5 we conclude
this paper.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Test Amplification: Small-Amp</title>
      <p>
        DSpot is an example of a test amplification tool
created for Java [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. We created Small-Amp as a
replication of DSpot for the Pharo Smalltalk ecosystem [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]
Small-Amp generates new test cases using an
evolutionary algorithm, to increase mutation coverage.
In this evolutionary algorithm, many versions of the
existing test methods are created by making small
changes on the test body (Input amplification). Then,
each test method is executed and the state of the
object under test is captured during the execution of the
test body. After that, the collected data obtained
from observations is used to insert new observation
statements in the test body (Assertion amplification).
Finally, the generated test methods are compared to
their original one (parent). If the generated method
improves the coverage, it will be promoted to the next
generation instead of its parent, else the generated test
method is ignored.
      </p>
      <p>
        With our Small-Amp tool prototype, we
demonstrated the feasibility of test amplification, even for a
dynamically types programming language [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
Nevertheless, we observed some areas for improvement. We
list them below.
• Type Information Dynamic languages lack type
information in the source code. So, during static
analysis, the type information is not directly
accessible. We need type information to add
new method calls during input amplification. In
Small-Amp we used a dynamic profiling step to
discover type information of variables in existing
test methods. But still, some methods are not
covered during the profiling step.
• State Information In order to generate valid
oracles, Small-Amp observes objects at run-time and
generate corresponding assert statements. For
capturing the state of the object under test, the
tool saves the values returned from getter
methods (methods in accessing protocol in the context
of Pharo). Unfortunately, there is no clear
distinction of which function serves as just a
getter and it doesn’t update the state of the object.
Furthermore, the tool generates the same assert
statements every time regardless of the previous
update statements.
• Readbility. The automatically generated test
cases are not easy to understand for humans. This
is especially worrisome because incomprehensible
test cases will not incorporated by test engineers.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Program Synthesis</title>
      <p>
        Program Synthesis is the task of automatically
creating programs from the underlying programming
language that satisfy user intent [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. This user intent
is typically expressed in some form of constraints like
input-output examples, demonstrations, natural
language, partial programs, and assertions.
      </p>
      <p>In this section, we enumerate a few recent advances
in the program synthesis area which may benefit test
amplification.
3.1</p>
      <sec id="sec-3-1">
        <title>Predicting Program Properties</title>
        <p>
          JSNice uses a probabilistic model that is learned
from existing data to predict the properties of new
programs[
          <xref ref-type="bibr" rid="ref5">5</xref>
          ]. The program properties can be classic
semantic properties like type annotation or syntactic
program elements like identifiers.
        </p>
        <p>
          DeepTyper is a similar tool, uses a deep learning
model that understands which types are most probable
used in certain contexts[
          <xref ref-type="bibr" rid="ref6">6</xref>
          ]. It can be applied to code
in Javascript and Python. To solve the problem of
type inference with machine learning, the authors got
inspiration from natural language processing, such as
part-of-speech tagging and named entity recognition.
3.2
        </p>
      </sec>
      <sec id="sec-3-2">
        <title>Code Completion</title>
        <p>
          Allamanis at al. used gated graph neural networks [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ]
to represent a snippet of a program code [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ]. This
graph includes relations between tokens like Child,
NextToken edges as well as LastUse, LastRead and
ComputedFrom to model program code as a graph.
Using such a deep learning model, they solved
VarNaming and VarMisuse problems. In VarMisuse problem,
a variable usage is masked, and the synthesizer is asked
to guess which variable is most suitable to use in the
hole.
        </p>
        <p>
          Raychev et al. reduced the problem of code
completion: given a program with holes, complete the holes
with the most likely sequence of method calls[
          <xref ref-type="bibr" rid="ref9">9</xref>
          ]. They
incorporated a natural language technique, predicting
probabilities of sentences. They construct a statistical
language model by extract a large number of
histories of API method calls from code snippets obtained
from Github and use regularities found in sequences of
method invocations to predict and synthesize a similar
method invocation sequence. This idea is implemented
in a tool called SLANG.
3.3
        </p>
      </sec>
      <sec id="sec-3-3">
        <title>Program Sketching</title>
        <p>
          In sketching, the programmer provides her/his
highlevel insights using partial programs, and the
synthesizer implements the low-level details. This low-level
implementation is generated using
counterexampleguided inductiove synthesis (CEGIS). The cegis
algorithm relies on an important empirical hypothesis; for
most sketches, only a small set of inputs is needed to
fully constrain the solution [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ].
3.4
        </p>
      </sec>
      <sec id="sec-3-4">
        <title>Learning to write code</title>
        <p>
          DeepCoder is an approach to write programs for
solving competition-style problems from input-output
examples [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ]. In this work, a simple Domain Specific
Language (DSL) is defined and DeepCoder solves the
problem by finding a program among all possible
programs that can be written using this language and can
produce desired outputs processing the inputs. For
minimizing the search space, they use a machine
learning model to predict which statements are most
probable to be used in the resulting program.
3.5
        </p>
      </sec>
      <sec id="sec-3-5">
        <title>Big Code</title>
        <p>
          In recent years, academics and practitioners have seen
arising the valuable resource of Big code. Big code
is the vast amount of code available on the web from
open source projects mainly hosted in publicly shared
repositories like Github. These projects contain not
only source code, but also the history of development,
issues, reported bugs and review processes. The
availability of big code suggests a new, data-driven
approach to developing software [
          <xref ref-type="bibr" rid="ref12">12</xref>
          ].
        </p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Program Synthesis For Test Amplification</title>
      <p>In this section we suggest some possible direction in
using program synthesis advances in test generations.
4.1</p>
      <sec id="sec-4-1">
        <title>Amplification in Dynamic Languages</title>
        <p>
          The type of objects in a dynamic language like
Javascript, Python and Pharo Smalltalk is not directly
accessible. Type information is helpful in the Input
amplification phase when the tool adds new method
calls to the test body to manipulate the state of the
object under test. Recent advances in type inference
[
          <xref ref-type="bibr" rid="ref6">6</xref>
          ] and predicting program properties [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ] are promising
to benefit type system information indirectly.
4.2
        </p>
      </sec>
      <sec id="sec-4-2">
        <title>Intelligent Assert Amplification</title>
        <p>
          Automatically generating test oracles, compared to
other aspects of software testing, has received less
attention [
          <xref ref-type="bibr" rid="ref13">13</xref>
          ].
        </p>
        <p>
          Using methods in [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ], [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ] and [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ] promises to find
patterns between updating methods sequence and the
asserted method considering the internal elements of
the object under test. Using these relations, the
amplifier can generate more relevant asserts regarding to
the updates on the object under test.
4.3
        </p>
      </sec>
      <sec id="sec-4-3">
        <title>Measuring the Readability of the Tests</title>
        <p>But there is a question: what is a readable test case?
A possible answer is a test case that is similar to the
test that is written by humans is readble.</p>
        <p>Benefiting from big code, we can mine existing test
case codes from open source project (Similar to [14])
to find some patterns in tests made by humans. Then,
we can rate generated test suites to find out how much
these tests are readable.
5</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Conclusions</title>
      <p>In this paper, we explore the benefits of using program
synthesis for test amplification. We discussed the
opportunity of using machine learning and big code to
improve the readability of amplified tests.</p>
      <p>We hope to hear from the community some related
ideas including introducing potential challenges, other
possible use cases, or any previous experiences on
using machine learning in generating code or software
testing.</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>This work is supported by (a) the Fonds de la Recherche
Scientifique-FNRS and the Fonds Wetenschappelijk
Onderzoek - Vlaanderen (FWO) under EOS Project 30446992</p>
      <p>SECO-ASSIST (b) Flanders Make vzw, the strategic
research centre for the manufacturing industry.</p>
      <p>[14] 2019.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Benjamin</given-names>
            <surname>Danglot</surname>
          </string-name>
          , Oscar Vera-Perez,
          <string-name>
            <given-names>Zhongxing</given-names>
            <surname>Yu</surname>
          </string-name>
          , Andy Zaidman,
          <string-name>
            <given-names>Martin</given-names>
            <surname>Monperrus</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Benoit</given-names>
            <surname>Baudry</surname>
          </string-name>
          .
          <article-title>A snowballing literature study on test amplification</article-title>
          .
          <source>Journal of Systems and Software</source>
          ,
          <volume>157</volume>
          :
          <fpage>110398</fpage>
          ,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Mehrdad</given-names>
            <surname>Abdi</surname>
          </string-name>
          , Henrique Rocha, and
          <string-name>
            <given-names>Serge</given-names>
            <surname>Demeyer</surname>
          </string-name>
          .
          <article-title>Test amplification in the pharo smalltalk ecosystem</article-title>
          .
          <source>In International Workshop on Smalltalk Technologies (IWST)</source>
          ,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Benjamin</given-names>
            <surname>Danglot</surname>
          </string-name>
          ,
          <string-name>
            <surname>Oscar Luis</surname>
            Vera-Pérez,
            <given-names>Benoit</given-names>
          </string-name>
          <string-name>
            <surname>Baudry</surname>
            , and
            <given-names>Martin</given-names>
          </string-name>
          <string-name>
            <surname>Monperrus</surname>
          </string-name>
          .
          <article-title>Automatic test improvement with dspot: a study with ten mature open-source projects</article-title>
          .
          <source>Empirical Software Engineering</source>
          ,
          <volume>24</volume>
          (
          <issue>4</issue>
          ):
          <fpage>2603</fpage>
          -
          <lpage>2635</lpage>
          ,
          <year>Apr 2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Sumit</given-names>
            <surname>Gulwani</surname>
          </string-name>
          , Oleksandr Polozov, and
          <string-name>
            <given-names>Rishabh</given-names>
            <surname>Singh</surname>
          </string-name>
          .
          <article-title>Program synthesis</article-title>
          .
          <source>Foundations and TrendsÂ® in Programming Languages</source>
          ,
          <volume>4</volume>
          (
          <issue>1</issue>
          -2):
          <fpage>1</fpage>
          -
          <lpage>119</lpage>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Veselin</given-names>
            <surname>Raychev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Martin</given-names>
            <surname>Vechev</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Andreas</given-names>
            <surname>Krause</surname>
          </string-name>
          .
          <article-title>Predicting program properties from big code</article-title>
          .
          <source>In ACM SIGPLAN Notices</source>
          , volume
          <volume>50</volume>
          , pages
          <fpage>111</fpage>
          -
          <lpage>124</lpage>
          . ACM,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Vincent</surname>
            <given-names>J Hellendoorn</given-names>
          </string-name>
          , Christian Bird,
          <string-name>
            <surname>Earl T Barr</surname>
            , and
            <given-names>Miltiadis</given-names>
          </string-name>
          <string-name>
            <surname>Allamanis</surname>
          </string-name>
          .
          <article-title>Deep learning type inference</article-title>
          .
          <source>In Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering</source>
          , pages
          <fpage>152</fpage>
          -
          <lpage>162</lpage>
          . ACM,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Yujia</given-names>
            <surname>Li</surname>
          </string-name>
          , Daniel Tarlow, Marc Brockschmidt, and Richard Zemel.
          <article-title>Gated graph sequence neural networks</article-title>
          .
          <source>arXiv preprint arXiv:1511.05493</source>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>Miltiadis</given-names>
            <surname>Allamanis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Marc</given-names>
            <surname>Brockschmidt</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Mahmoud</given-names>
            <surname>Khademi</surname>
          </string-name>
          .
          <article-title>Learning to represent programs with graphs</article-title>
          .
          <source>In International Conference on Learning Representations</source>
          ,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Veselin</given-names>
            <surname>Raychev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Martin</given-names>
            <surname>Vechev</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Eran</given-names>
            <surname>Yahav</surname>
          </string-name>
          .
          <article-title>Code completion with statistical language models</article-title>
          .
          <source>In Acm Sigplan Notices</source>
          , volume
          <volume>49</volume>
          , pages
          <fpage>419</fpage>
          -
          <lpage>428</lpage>
          . ACM,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>Armando</given-names>
            <surname>Solar-Lezama</surname>
          </string-name>
          .
          <article-title>Program sketching</article-title>
          .
          <source>International Journal on Software Tools for Technology Transfer</source>
          ,
          <volume>15</volume>
          (
          <issue>5-6</issue>
          ):
          <fpage>475</fpage>
          -
          <lpage>495</lpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Matej</surname>
            <given-names>Balog</given-names>
          </string-name>
          , Alexander L Gaunt, Marc Brockschmidt,
          <string-name>
            <given-names>Sebastian</given-names>
            <surname>Nowozin</surname>
          </string-name>
          , and Daniel Tarlow.
          <article-title>DeepCoder: Learning to write programs</article-title>
          .
          <source>In 5th International Conference on Learning Representations (ICLR)</source>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Miltiadis</surname>
            <given-names>Allamanis</given-names>
          </string-name>
          , Earl T. Barr, Premkumar Devanbu, and
          <string-name>
            <given-names>Charles</given-names>
            <surname>Sutton</surname>
          </string-name>
          .
          <article-title>A survey of machine learning for big code and naturalness</article-title>
          .
          <source>ACM Computing Surveys</source>
          ,
          <volume>51</volume>
          (
          <issue>4</issue>
          ):
          <fpage>1</fpage>
          -
          <lpage>37</lpage>
          ,
          <year>Jul 2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Earl</surname>
            <given-names>T Barr</given-names>
          </string-name>
          , Mark Harman,
          <string-name>
            <surname>Phil</surname>
            <given-names>McMinn</given-names>
          </string-name>
          ,
          <string-name>
            <given-names>Muzammil</given-names>
            <surname>Shahbaz</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Shin</given-names>
            <surname>Yoo</surname>
          </string-name>
          .
          <article-title>The oracle problem in software testing: A survey</article-title>
          .
          <source>IEEE transactions on software</source>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>