chapter eight

8 Building Effective Tests with Generative AI

 

This chapter covers

  • Overview of using Generative AI Tools for Test Generation
  • Exploring three popular tools for test generation
  • Step by step examples of creating unit tests for each tool
  • Creating in memory databases for testing
  • Writing the best prompts for each tool
  • Strengths and weaknesses of each tool

Software applications are becoming more complex every day. Creating and maintaining tests is getting more complex as well. But what exactly are software tests? Tests are tools build with software, usually in the same language and packaged with the software. They help developers verify that their code works. They’re a safety net to help you build confidence that your software is functioning as expected. They not only tell you the software you’re about to release is trustworthy. They’ll also tell you if something you add or change to the software breaks something that was working before.

High-quality tests are crucial for software reliability. They help catch bugs early. They ensure new features don't break existing code. They also document how the code should behave. As a newer developer, I initially struggled to see the value of testing. I thought spending time creating tests to check code I knew was good was unnecessary. It didn't take long for me to see the error in my thinking. You only need one good disaster to change your mind.

8.1 Why use Generative AI for Testing?

8.2 What are Unit Tests?

8.3 The Tools we’ll use for Python Testing

8.4 Writing Unit Tests with Generative AI

8.4.1 Unittest or Pytest?

8.4.2 Using Copilot for test generation

8.4.3 Leveraging Tabnine for test generation

8.4.4 Applying BlackboxAI for test generation

8.4.5 Which tool should you use for testing?

8.5 Summary