Pair Programming and test-driven development with Visual Studio Live Share and GitHub Copilot
Published Feb 18 2023 12:00 AM 5,598 Views
Microsoft

Pair programming is a software development technique in which two developers work together on the same code at the same time, with one typing and the other reviewing and offering suggestions. This technique can increase productivity and promote knowledge sharing, as well as improve code quality through increased collaboration and code review.


Test-driven development (TDD) is a software development process in which tests are written before writing the actual code. The tests serve as a guide for the development process and help ensure that the code meets the requirements and behaves as expected. The TDD cycle consists of writing a test, running it to see if it fails, writing the minimum amount of code needed to make the test pass, and then repeating this process until all tests pass and the code is complete.

 

GitHub Copilot is a tool that can be used to support pair programming and TDD. It allows developers to collaborate in real-time on the same codebase and provides an environment for running tests and code review. This can help teams work more efficiently and effectively, especially for remote teams who may be working from different locations. Additionally, Copilot can also assist with automated code suggestions and recommendations based on best practices, further improving code quality and efficiency. 

 

In summary, pair programming and TDD are valuable software development techniques that can enhance the development process, and GitHub Copilot can help teams effectively utilize these practices to produce high-quality code.has context menu

 

Getting Started 

To get started with activating your FREE GitHub Copilot 
Download GitHub Copilot for VS Code
Download GitHub Copilot Labs for VS Code

 

GitHub Copilot is a simple, powerful way to use GitHub for automated, test-driven development. It provides an easy-to-use framework for writing, running, and monitoring tests, as well as an integrated interface for managing the entire development process.

 

To get started with GitHub Copilot, first create your GitHub account and activate your copilot subscription. Create a new repository in GitHub and add the Copilot extension, then, create your test files and add code to run the tests many academic institutions introduce test driven development in classes which use pair programming.

Pair programming is a popular Agile technique that involves two developers working on the same piece of functionality together. In many cases this is used in lab exercises to help student identify bugs and gain understanding of reading and documenting codes bases.

The benefits of pair programming include:

  •  Quality of produced code should be higher as two developers have been involved and verified code.
  • Increased awareness and understanding of the codebase across the team which leads to improved experiences and documentation.
  • Skilling and sharing of best practices which lead to higher quality and greater collaboration.

During COVID many courses lost the opportunity of students being with other students in the same room looking at the same screen, thankfully tools like VSCode LiveShare faciliated students to keep pair programming and allowed students to communicate not only screen share but also via voice. 

LeeStott_0-1676415449791.gif


Allowing students to give peer feedback on code, discover underlying issues, and support the coder/driver in successful development.

Many benefits of pair programming are only seen when it’s done as a collaborative team effort. On the other hand, artificial intelligence may potentially give you a real virtual tutor or assistant. We have found GitHub Copilot works really well at increasing your productivity, and also helping.

 

How to generate tests and test data

 

Students often need to think of sample data for your tests, documentation, or default settings. In many cases this results in a burden for the course tutor or academic to validate the data or in some case even produce the sample data sets.

GitHub Copilot is an amazing support asset. For example, your student need a set of personnal data record for there application development. 

The task set has a Person class:

 

from dataclasses import dataclass
from datetime import date

@dataclass
class Customers:
    first_name: string
    last_name: string
    birth_date: date

    def age(self):
        return (date.today() - self.birth_date).days // 365

    @property
    def full_name(self):
        return f"{self.first_name} {self.last_name}"

What you now need is a selection of data for this class did you know you can used GitHub Copilot to populate a list of Sales details.

So if your starting from nothing you can simply ask copilot to create a data set. 

 

// create me a list of people based on first_name:string, last_name:string, birth_date:date
Sales = [      
    { "first_name": "John", "last_name": "Doe", "birth_date": "1970-01-01" },
    { "first_name": "Jane", "last_name": "Doe", "birth_date": "1970-01-02" },
    { "first_name": "John", "last_name": "Smith", "birth_date": "1970-01-03" },
    { "first_name": "Jane", "last_name": "Smith", "birth_date": "1970-01-04" },
    { "first_name": "John", "last_name": "Doe", "birthdate": "1970-01-05" },
    { "first_name": "Jane", "last_name": "Doe", "birthdate": "1970-01-06" },
    { "first_name": "John", "last_name": "Smith", "birthdate": "1970-01-07" },
]

GitHub Copilot successfully figured out to use your Person class for the Sales list elements. 

 

If you all ready have the reference code, you simply need to Declare an empty Python list using an expressive variable name, and hit Enter just after the opening square bracket ([) to trigger the suggestions:

Customers = [

As you keep hitting Tab after each suggested line, you might end up with the following list of employees: and then close ]

 

Creating a Test Driven Development

You can use that list as a common test fixture for a group of test cases that require it.  GitHub Copilot can be an excellent help in the testing process itself by suggesting both tests and the code under test.

 

Exercise Test-Driven Development (TDD)

Briefly, the TDD process:

  • Write a failing test case that you have too satisfy
  • Implement the smallest amount of code to make your test case pass
  • Optionally, refactor the code while all your test cases are still passing
  • Then, rinse and repeat!
  • As long as you’re disciplined enough to stay in this perpetual cycle, you’ll write testable code that has high test coverage and documents itself.

 

So an example we want to create and test a HashTable implementation, using GitHub Copilot as your virtual pair programmer?

Step 1. Create two empty Python files next to each other in the same folder:

src/
├── hashtable.py
└── test_hashtable.py


The hashtable.py code under test. The test_hashtable.py is the home of your test cases driving the implementation. 

LeeStott_0-1675975944904.png

 

Automation of TDD

 

Once you have set up your tests, you can use the Copilot interface to manage and monitor your testing process. This includes running tests, viewing results, and tracking progress. GitHub Copilot also integrates with popular continuous integration (CI) tools like Jenkins, Travis CI, and CircleCI, allowing you to easily integrate tests into your development workflow.


To help ensure that your tests are up-to-date, Copilot can be configured to run automatically on a regular basis, such as after each commit or nightly. This helps keep your tests and code in sync and ensures that any bug fixes are applied quickly.

 

Conclusion 

 

There are several reasons why students should use GitHub Copilot for TDD and virtual pair programming:

 

  • Improved Code Quality: By incorporating TDD and pair programming into the development process, students can ensure that their code meets the requirements and behaves as expected. They can also catch and fix any bugs or issues early on in the development process.
  • Enhanced Collaboration: GitHub Copilot provides an environment for real-time collaboration, allowing students to work together on the same codebase and share ideas and knowledge with each other. This can lead to a more efficient development process and can help students learn from each other.
  • Remote Work Support: With the increasing popularity of remote work, virtual pair programming has become an important tool for development teams. GitHub Copilot allows students to work together, even when they are in different locations, which can help them collaborate effectively and build a better understanding of each other's strengths and weaknesses.
  • Automated Code Suggestions: GitHub Copilot provides automated code suggestions and recommendations based on best practices, which can help students write better code and improve their coding skills.
  • Real-World Experience: Using GitHub Copilot for TDD and virtual pair programming gives students a taste of what it's like to work on real-world software development projects. Students can apply the skills they've learned in the classroom to real-world situations and gain hands-on experience.

GitHub Copilot is a great tool for developers who want to take advantage of test-driven development and automated testing. It provides an easy-to-use interface and powerful features to help developers quickly and easily create, run, and monitor tests. Copilot is FREE for students and educators and enables educators and students to practice and improve their TDD and pair programming skills, which can help them build better software and enhance their career prospects. 

Co-Authors
Version history
Last update:
‎Feb 15 2023 11:02 AM
Updated by: