Automatic Unit Test Generation for Deep Learning Frameworks based on API Knowledge

Many automatic unit test generation tools that can generate unit test cases with high coverage over a program have been proposed. However, most of these tools are ineffective on deep learning (DL) frameworks due to the fact that many of deep learning APIs expect inputs that follow specific API knowledge. To fill this gap, we propose MUTester to generate unit test cases for APIs of deep learning frameworks by leveraging the API constraints mined from the corresponding API documentation and the API usage patterns mined from code fragments in Stack Overflow (SO). Particularly, we first propose a set of 18 rules for mining API constraints from the API documents. We then use the frequent itemset mining technique to mine the API usage patterns from a large corpus of machine learning API related code fragments collected from SO. Finally, we use the above two types of API knowledge to guide the test generation of existing test generators for deep learning frameworks. To evaluate the performance of MUTester, we first collect 1,971 APIs from four widely-used deep learning frameworks (i.e., Scikit-learn, PyTorch, TensorFlow, and CNTK) and for each API, we further extract its API knowledge, i.e., API constraints and API usage. Given an API, MUTester combines its API knowledge with existing test generators (e.g., search-based test generator PyEvosuite and random test generator PyRandoop) to generate test cases to test the API. Results of our experiment show that MUTester can significantly improve the corresponding test generation methods and the improvement in code coverage is 15.7 invalid tests generated by the existing test generators. Our user study with 16 developers further demonstrates the practicality of MUTester in generating test cases for deep learning frameworks.

READ FULL TEXT
research
09/02/2021

Leveraging Documentation to Test Deep Learning Library Functions

It is integral to test API functions of widely used deep learning (DL) l...
research
07/30/2022

Mining unit test cases to synthesize API usage examples

Software developers study and reuse existing source code to understand h...
research
03/07/2023

ADELT: Transpilation Between Deep Learning Frameworks

We propose Adversarial DEep Learning Transpiler (ADELT) for source-to-so...
research
12/20/2019

QuickREST: Property-based Test Generation of OpenAPI-Described RESTful APIs

RESTful APIs are an increasingly common way to expose software systems f...
research
03/24/2023

Improving API Documentation Comprehensibility via Continuous Optimization and Multilingual SDK

Optimizing and maintaining up-to-date API documentation is a challenging...
research
03/23/2023

gDoc: Automatic Generation of Structured API Documentation

Generating and maintaining API documentation with integrity and consiste...
research
06/04/2019

Bridging the Gap between Unit Test Generation and System Test Generation

Common test generators fall into two categories. Generating test inputs ...

Please sign up or login with your details

Forgot password? Click here to reset