Prompt files are a powerful way to create standardized, reusable prompts that can be shared across your team. They help ensure consistency in how you interact with GitHub Copilot and can encode best practices for common tasks like code generation, testing, and documentation.
In this part, you'll create a reusable prompt file for generating unit tests and use it to add tests to the existing TinyShop.Tests project.
Prompt files are markdown files stored in the .github/prompts folder of your repository. They:
- Can be invoked by name in Copilot Chat
- Are shared with your entire team through source control
- Can include placeholders for dynamic content
- Help standardize common development tasks
The solution already includes a TinyShop.Tests project with MSTest configured. Let's take a look at what's there.
- [] In Solution Explorer, expand the TinyShop.Tests project.
- [] Open ProductTests.cs to see the existing reference test.
- [] Notice the test follows the Arrange-Act-Assert pattern and verifies default values for a new Product instance.
Now let's create a prompt file that helps generate additional unit tests using MSTest.
-
[] In Solution Explorer we will see the GitHub node from the extension to add it easily:
- Right-Click the GitHub node icon/extension in Visual Studio.
- Choose Add Copilot File....
- Select Prompt file... from the dialog.
- Change the file name to
unit-test.prompt.mdand click OK. - The new file will open in the editor; paste the content shown below into the file and save it.
-
[] If you can create the file manually in file explorer, add a new file named
unit-test.prompt.mdunder.github/promptsand paste the content below. -
[] Update the prompt file with the following content:
--- mode: agent description: Generate comprehensive unit tests using MSTest --- # Unit Test Generator Generate unit tests for the selected code using the MSTest framework. ## Requirements - Use MSTest attributes ([TestClass], [TestMethod], [DataRow]) - Follow the Arrange-Act-Assert pattern - Include both positive and negative test cases - Test edge cases and boundary conditions - Use descriptive test method names that explain what is being tested - Mock dependencies where appropriate ## Test Structure Each test should: 1. Have a clear name following the pattern: `MethodName_Scenario_ExpectedBehavior` 2. Include a brief comment explaining the test purpose 3. Use proper assertions with meaningful failure messages ## Context Generate tests for: ${input:Describe what you want to test}
-
[] Save the file.
Now let's use our new prompt file to generate additional unit tests for the Product class.
-
[] In Copilot Chat, type
/to see available prompt files. -
[] Select
unit-testfrom the list of available prompts. -
[] When prompted for input, type:
the Product class in DataEntities, including tests for setting and getting each property, and tests using DataRow for multiple values -
[] Review the generated tests. They should include:
- Tests for each property (Name, Description, Price, ImageUrl)
- Tests using DataRow for parameterized testing
- Proper test method naming following the pattern
- Comments explaining test purposes
The generated tests should look similar to:
[TestMethod]
public void Name_SetValue_ReturnsExpectedValue()
{
// Arrange
var product = new Product();
var expectedName = "Test Product";
// Act
product.Name = expectedName;
// Assert
Assert.AreEqual(expectedName, product.Name);
}
[TestMethod]
[DataRow(19.99)]
[DataRow(0)]
[DataRow(999.99)]
public void Price_SetValue_ReturnsExpectedValue(double price)
{
// Arrange
var product = new Product();
var expectedPrice = (decimal)price;
// Act
product.Price = expectedPrice;
// Assert
Assert.AreEqual(expectedPrice, product.Price);
}
[TestMethod]
[DataRow("product1.png")]
[DataRow("product2.png")]
[DataRow("")]
public void ImageUrl_SetValue_ReturnsExpectedValue(string imageUrl)
{
// Arrange
var product = new Product();
// Act
product.ImageUrl = imageUrl;
// Assert
Assert.AreEqual(imageUrl, product.ImageUrl);
}- [] Open Test Explorer from Test -> Test Explorer.
- [] Build the solution to discover the tests.
- [] Click Run All to run all tests including the new generated tests.
- [] Verify that all tests pass.
Key Takeaway: Reusable prompt files help standardize how your team uses GitHub Copilot. By creating prompts for common tasks like unit testing, you ensure consistency and encode best practices that everyone on the team can benefit from.
Back: Part 10 - Planning Mode in Agent ← | Next: Part 12 - Delegate to the Cloud →
