Get startedGet started for free

Testing and code quality with Copilot

1. Testing and code quality with Copilot

Welcome back! This chapter is where things get really practical. We're putting everything we've learned about Copilot to work on real development challenges.

2. What you've learned

In the previous chapters, we explored what Copilot can do, from code completions and chat to agent mode and custom tools. That's a powerful foundation.

3. Now, let's apply it

Now it's time to put those capabilities to work. In this chapter, we'll apply Copilot to three critical areas of software development: testing, security, and performance. Let's start with testing.

4. Copilot makes testing easier

As we saw in previous videos, Copilot can generate full test suites, catch edge cases you'd miss, and handle the tedious boilerplate — so you can focus on the logic that matters. Now let's go deeper into how, starting with a problem every developer knows well.

5. The edge cases that slip through

Let's look at a discount calculator. It works for the straightforward case — 20% off a $50 item gives you $40. But what about a negative price? A discount of 110%? An order with zero items? These edge cases sneak into production. And when they do, you're the one debugging them at 11 p.m.

6. Enter /tests

You've already seen the slash-tests command earlier in the course. It's the quickest path to a full test suite. Just type slash-tests in the chat, and Copilot analyzes the file, identifies the edge cases, and generates everything you need. No extra context required.

7. Here's what that looks like

Here's the output. Copilot generates a pytest file with a comprehensive test suite for both the "apply bulk discount" and "calculate discount" functions. It picks the right assertion style and names the tests so you can actually tell what they're checking. It even creates the test file structure from scratch — you don't need to set up the boilerplate yourself.

8. When to go deeper

So when is slash-tests enough, and when do you need more? For straightforward functions, slash-tests does a great job on its own. But when you have specific scenarios in mind, a detailed prompt - like the one seen on screen - gives you much more control. Specify the framework, the edge cases, and the patterns you need.

9. Beyond unit tests

Copilot works across the full testing pyramid: unit, integration, and end-to-end. The key difference is how much context you give it. Unit tests are self-contained, so a simple prompt is enough. Integration and end-to-end tests span multiple files and components, so you'll need to point Copilot in the right direction. Let's look at exactly how to do that.

10. Integration tests

For integration tests, Copilot needs to know which components are involved. Attach each relevant file with hash-file, describe the interaction, and specify your mocking strategy — the more specific you are, the more realistic the tests. And if something breaks after generation, slash-fixTestFailure will diagnose the failure and suggest a fix.

11. End-to-end tests

For end-to-end tests, @workspace handles the heavy lifting — just describe the user flow and Copilot discovers your codebase automatically. It pairs especially well with Playwright and Cypress, GitHub's recommended end-to-end frameworks. And if a test fails, attach the terminal output with hash-terminalLastCommand so Copilot can diagnose and fix it right there in the chat.

12. Improving tests you already have

Copilot isn't just for writing tests from scratch, it can also help you enhancing existing tests. Select an existing test and ask it to improve coverage, tighten the assertions, or refactor for readability. This is especially useful when you've inherited a test suite that has low coverage. A few targeted prompts can bring it up to scratch without a full rewrite.

13. Let's practice!

Time to put Copilot's testing skills to work — let's go!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.