liveBook · Manning

Chapter 8: Building effective tests with generative AI

What you will learn in chapter 8 of Coding with AI

The chapter introduces why testing matters and how generative AI can make writing thorough tests faster.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces why testing matters and how generative AI can make writing thorough tests faster.

Key terms: tests, reliable software, generative AI, boilerplate, test cases, coverage

8.1 Why use generative AI for testing?

This section explains why AI-generated tests can improve development speed and feedback while requiring care with their risks.

Key terms: AI-generated scaffolding, test generation, faster feedback loop, unit test, context, code review, careful prompt design

8.2 What are unit tests?

Defines unit tests as focused checks of individual pieces of code and explains how they help catch bugs before release.

Key terms: unit tests, functions, classes, assert, bugs, reasonably stable

8.3 The tools we’ll use for Python testing

Introduces the AI tools the chapter will use for test generation and previews a comparison of their approaches.

8.3.1 Github Copilot

This subsection identifies ways to use GitHub Copilot for test generation and briefly lists its advantages.

Key terms: GitHub Copilot, chat-style interface, IDE, API, agent mode

8.3.2 Tabnine

The section introduces Tabnine as a test-generation tool and lists ways to use it and advantages it offers.

Key terms: Tabnine, test generation, IDE, chat interface, local models

8.3.3 Blackbox AI

This subsection introduces Blackbox AI’s IDE and chat options and highlights its context-aware chat and test-focused agents.

Key terms: Blackbox AI, VS Code Chat, context, Customized agents

8.4 Writing unit tests with generative AI

This introduction notes that the AI tools tend to generate unittest tests by default and previews a comparison with pytest.

Key terms: unittest, pytest

8.4.1 unittest or pytest?

Compares unittest and pytest and explains why the chapter uses pytest to explore AI-generated tests.

Key terms: unittest, pytest, plain asserts, test discovery, fixture system

8.4.2 Using Copilot for test generation

The section walks through using GitHub Copilot to build pytest tests, correcting its suggestions and refining the test setup and assertions.

Key terms: pytest, virtual environment, test_, GitHub Copilot, /tests, unittest, prompt, context, in-memory database, SQLite

8.4.3 Using Tabnine for test generation

This section demonstrates how Tabnine proposes tests from existing code and tests, then lets the developer refine a generated test to fit the project's pytest setup.

Key terms: test shortcut, existing test file, test plan, suggested tests, unittest, pytest, Mock, fixture, in-memory database, test ordering

8.4.4 Applying Blackbox AI for test generation

This section shows how Blackbox AI uses application context to generate tests for the Questions class, then explains how to steer its results with a more specific prompt or agent.

Key terms: Blackbox AI, Chat with Your Code Files, Questions class, in-memory database, unittest, pytest, pytest.fixture, assert, prompt, Blackbox AI agent

8.4.5 Which tool should you use for testing?

This section compares three AI testing tools and gives a human-guided workflow for generating effective tests.

Key terms: GitHub Copilot, Tabnine, Blackbox AI, cloud-based, on-premises, AI test generation workflow, scaffold, fixtures, edge cases, boundary conditions

8.5 Summary

Concepts explained in this chapter

← Chapter 7: Building user interfaces with ChatGPT Chapter 9: Prompt engineering →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.