Skip to main content

Automate the Annoying Stuff: Writing Tests & Docs with AI

So far, we've focused on using AI to write application code. But some of the biggest productivity wins come from using AI to automate the tasks around coding—the things you know you should do, but that often feel like a chore.

Let's explore how your AI assistant can become an expert at writing tests and documentation, saving you time and mental energy.

1. Generate Unit Tests Instantly

Writing tests is crucial for robust software, but it can be repetitive. This is a perfect task for an AI. Once you have a function that works, you can ask your AI to handle the testing.

The Workflow:

  1. Write or select a function in your editor.
  2. Open the AI chat panel.
  3. Use a prompt like this:

Prompt:

Please write a comprehensive set of unit tests for this function using the [Jest/Pytest/etc.] framework. Include tests for the happy path, invalid inputs, and any important edge cases.

In seconds, you'll have a solid test file that you can review, adjust, and save. This not only saves time but also often results in more thorough test coverage, as the AI will think of edge cases you might have missed.

2. Never Write Boilerplate Docs Again

Good documentation is essential for maintainable code, but writing it can be tedious. Your AI can instantly generate high-quality documentation for any piece of code.

The Workflow:

  1. Highlight a function, class, or method.
  2. Use a prompt like this:

Prompt:

Write a JSDoc comment block for this function. Make sure to describe what the function does, and detail each parameter and the return value.

The AI will generate a perfectly formatted comment block that you can drop right into your code. This is especially powerful for documenting complex functions or public APIs.

3. Understand Legacy Code in Seconds

Ever been assigned a bug in a file you've never seen before? Instead of spending an hour deciphering complex logic, you can ask your AI to be your guide.

The Workflow:

  1. Highlight the confusing block of code.
  2. Ask a simple question:

Prompt:

Can you please explain what this code does in simple terms?

Your AI can untangle complex regular expressions, explain archaic algorithms, and give you a high-level summary of what a file is trying to accomplish, dramatically speeding up your ability to work with unfamiliar code.

By offloading these tasks to your AI, you free up your brainpower to focus on what matters most: solving interesting problems and building great software.

In our final post of this series, we'll look at how to keep your skills sharp in the rapidly evolving world of AI.