Test Driven Development (TDD) is one of the major practices of Extreme Programming for which incremental testing and refactoring trigger the code development. TDD has limited adoption in the industry, as it requires more code to be developed and experienced developers. Generative AI (GenAI) may reduce the extra effort imposed by TDD. In this work, we introduce an approach to automatize TDD by embracing GenAI either in a collaborative interaction pattern in which developers create tests and supervise the AI generation during each iteration or a fully-automated pattern in which developers only supervise the AI generation at the end of the iterations. We run an exploratory experiment with ChatGPT in which the interaction patterns are compared with the non-AI TDD regarding test and code quality and development speed. Overall, we found that, for our experiment and settings, GenAI can be efficiently used in TDD, but it requires supervision of the quality of the produced code. In some cases, it can even mislead non-expert developers and propose solutions just for the sake of the query.
翻译:测试驱动开发(TDD)是极限编程的主要实践之一,其通过增量测试和重构驱动代码开发。由于需要开发更多代码并且要求开发者具备丰富经验,TDD在工业界的采用有限。生成式人工智能(GenAI)可能减少TDD带来的额外工作量。本文提出了一种通过借助GenAI自动化TDD的方法,该方法可采用协作交互模式(开发者在每次迭代中创建测试并监督AI生成)或全自动模式(开发者仅在迭代结束时监督AI生成)。我们使用ChatGPT开展了探索性实验,将这两种交互模式与非AI的TDD在测试与代码质量及开发速度方面进行了比较。总体而言,我们发现对于我们的实验设置,GenAI可有效用于TDD,但需对生成代码的质量进行监督。在某些情况下,它甚至可能误导非专业开发者,并仅为满足查询而提出解决方案。