TDD with CoPilot

Puran Joshi
3 min readJun 30, 2023

--

Coding along side AI

Audience

Software engineers who are interested in Test-Driven Development (TDD) and seeking to improve their efficiency, as well as those who dislike composing repetitive and standard code.

Overview

Before we start I wanted to mention that I will not delve deeply into Test-Driven Development (TDD) since I assume that you are already familiar with it. However, if you are not familiar with TDD, I recommend listening to Uncle Bob’s explanation of the concept.

My main objective is to demonstrate how CoPilot can be utilised during software development using the Test-Driven Development (TDD) approach.

But before we go into this topic let me introduce you to coPilot.

CoPilot

CoPilot is a powerful code editor extension that provides AI-powered code suggestions and autocompletion, making it an excellent tool for streamlining Test-Driven Development (TDD) and enhancing productivity. It is a paid tool that needs to be purchased separately.

Some of the features of coPilot are

  • AI-powered code suggestions and autocompletion
  • Support for multiple programming languages, including Python, JavaScript, TypeScript, Ruby, and more
  • Customisable code snippets and templates for faster coding
  • Real-time collaboration with other developers using Live Share
  • Code analysis and error detection to help catch mistakes early
  • Integration with popular code editors, including IntelliJ, Visual Studio Code and Atom

Please note just like any machine learning model, coPilot has been trained on a vast amount of open-source code available on the internet. The model has been trained to recognise patterns in code and generate suggestions based on those patterns. As you keep writing code using CoPilot, the tool continues to learn and improve its suggestions. This means that over time, CoPilot becomes more accurate and can provide you more relevant suggestions. Additionally, CoPilot allows you to provide feedback on its suggestions, which can further improve the accuracy of its machine learning model.

Let’s take a look at a demonstration of how CoPilot can assist me during the coding process.

Demonstration

Problem Statement

I want to write a URL shortening service that allows users to shorten long URLs into short and easy-to-remember links.

Note - The video aims to demonstrate a pragmatic approach to writing controllers using Test-Driven Development (TDD) with the assistance of CoPilot’s code suggestion feature

Youtube link to see live demonstration

Highlights

  1. coPilot has the ability to suggest test code based on the name of the test method, as shown below.

2. Also, helps you with writing the code to fix it

3. Just start writing the mock and it will help you complete them

4. Furthermore, coPilot can provide suggestions on your next potential test scenario.

However if you want to look at the source code feel free to checkout this GitHub Link

While CoPilot is a relatively new tool and has room for improvement, it has already proven to be beneficial in increasing my productivity by at least a certain percentage.

--

--

Puran Joshi

Experienced Software Engineer & Technical Lead | Expertise in Full-stack Development, Object Oriented Programming, Agile Methodologies, and Team Leadership