单元测试生成的自动化支持:教程章节
Automated Support for Unit Test Generation: A Tutorial Book Chapter
摘要:
单元测试是测试的一个阶段,在这个阶段中,可以与系统的其余部分(通常是一个类)隔离测试的最小代码段被测试。单元测试通常以可执行代码的形式编写,通常采用单元测试框架(如Python的pytest)提供的格式。创建单元测试是一个时间和精力密集型的过程,其中包含许多重复的手动元素。为了说明AI如何支持单元测试,本章介绍了基于搜索的单元测试生成的概念。这种技术框架的测试输入的选择作为一个优化问题-我们寻求一组测试用例,满足测试人员的一些可衡量的目标-并释放强大的元启发式搜索算法,以确定最好的测试用例在有限的时间范围内。本章介绍了两种算法,它们可以生成pytest格式的单元测试,并针对源代码语句的覆盖率进行了调整。本章最后讨论了更高级的概念,并为进一步阅读人工智能如何在单元测试软件时支持开发人员和测试人员提供了指针。
英文摘要:
Unit testing is a stage of testing where the smallest segment of code that can be tested in isolation from the rest of the system - often a class - is tested. Unit tests are typically written as executable code, often in a format provided by a unit testing framework such as pytest for Python. Creating unit tests is a time and effort-intensive process with many repetitive, manual elements. To illustrate how AI can support unit testing, this chapter introduces the concept of search-based unit test generation. This technique frames the selection of test input as an optimization problem - we seek a set of test cases that meet some measurable goal of a tester - and unleashes powerful metaheuristic search algorithms to identify the best possible test cases within a restricted timeframe. This chapter introduces two algorithms that can generate pytest-formatted unit tests, tuned towards coverage of source code statements. The chapter concludes by discussing more advanced concepts and gives pointers to further reading for how artificial intelligence can support developers and testers when unit testing software.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。