You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lab/part11-reusable-prompts.md
+59-65Lines changed: 59 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
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.
4
4
5
-
In this part, you'll create a reusable prompt file for generating unit tests and use it to test the Product class in the TinyShop application.
5
+
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.
6
6
7
7
## Understanding Prompt Files
8
8
@@ -12,9 +12,17 @@ Prompt files are markdown files stored in the `.github/prompts` folder of your r
12
12
- Can include placeholders for dynamic content
13
13
- Help standardize common development tasks
14
14
15
+
## Exploring the Test Project
16
+
17
+
The solution already includes a **TinyShop.Tests** project with MSTest configured. Let's take a look at what's there.
18
+
19
+
1.[] In **Solution Explorer**, expand the **TinyShop.Tests** project.
20
+
1.[] Open **ProductTests.cs** to see the existing reference test.
21
+
1.[] Notice the test follows the Arrange-Act-Assert pattern and verifies default values for a new Product instance.
22
+
15
23
## Creating a Unit Test Prompt File
16
24
17
-
Let's create a prompt file that helps generate unit tests using MSTest.
25
+
Now let's create a prompt file that helps generate additional unit tests using MSTest.
18
26
19
27
1.[] In **Solution Explorer**, right-click on the solution and select **Add -> New Folder** and name it `.github` if it doesn't already exist.
20
28
1.[] Right-click on the `.github` folder and select **Add -> New Folder** and name it `prompts`.
@@ -54,94 +62,80 @@ Let's create a prompt file that helps generate unit tests using MSTest.
54
62
55
63
1.[] Save the file.
56
64
57
-
## Setting Up a Test Project
58
-
59
-
Before we can use our prompt, we need a test project. Let's create one using Copilot Agent.
60
-
61
-
1.[] Open Copilot Chat and switch to **Agent** mode.
62
-
1.[] Type: `Create a new MSTest project called TinyShop.Tests in the src folder and add it to the solution. Add a reference to the DataEntities project.`
63
-
1.[] Accept the changes proposed by Copilot.
64
-
65
65
## Using the Reusable Prompt
66
66
67
-
Now let's use our new prompt file to generate unit tests for the Product class.
67
+
Now let's use our new prompt file to generate additional unit tests for the Product class.
68
68
69
69
1.[] In Copilot Chat, type `/` to see available prompt files.
70
70
1.[] Select `unit-test` from the list of available prompts.
71
-
1.[] When prompted for input, type: `the Product class in DataEntities, including tests for property getters/setters and validation of the Price property (should be non-negative)`
71
+
1.[] 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`
72
72
73
73

74
74
75
75
1.[] Review the generated tests. They should include:
76
-
- Tests for each property
77
-
- Tests for edge cases (empty strings, null values)
78
-
-Tests for price validation
79
-
-Proper test method naming
76
+
- Tests for each property (Name, Description, Price, ImageUrl)
1.[] Open **Test Explorer** from **Test -> Test Explorer**.
143
137
1.[] Build the solution to discover the tests.
144
-
1.[] Click **Run All** to run the generated tests.
138
+
1.[] Click **Run All** to run all tests including the new generated tests.
145
139
1.[] Verify that all tests pass.
146
140
147
141
**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.
0 commit comments