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: README.md
+38-22Lines changed: 38 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,10 @@ Try different things and see what GitHub Copilot can do for you, like generating
8
8
9
9
> Make sure GitHub Copilot is configure and enabled for the current laguage, just check the status bar on the bottom right corner of VS Code.
10
10
11
+
> If you are running this exercise in local environment, please make sure JDK 18 and above is installed.
12
+
13
+
> If you are running this exercise in GitHub Codespaces, the java environment is already setup.
14
+
11
15
## Instructions
12
16
13
17
The `copilot-demo` folder contains the Maven project and Maven installer.
@@ -19,17 +23,17 @@ The `copilot-demo` folder contains the Maven project and Maven installer.
19
23
20
24
To run Copilot inline on Windows you press `Ctrl + i` (Windows) / `⌘ + i` (Mac)
21
25
22
-
To run the tests open a terminal in the `copilot-demo` folder and run:
26
+
To run the app open a terminal in the `copilot-demo` folder and run:
23
27
24
28
```sh
25
-
./mvnw test
29
+
./mvnw package
30
+
./mvnw spring-boot:run
26
31
```
27
32
28
-
To run the app open a terminal in the `copilot-demo` folder and run:
33
+
To run the tests open a terminal in the `copilot-demo` folder and run:
29
34
30
35
```sh
31
-
./mvnw package
32
-
./mvnw spring-boot:run
36
+
./mvnw test
33
37
```
34
38
35
39
### Unix Note
@@ -41,13 +45,26 @@ Please run the following to give it execute permissions.
41
45
chmod +x ./mvnw
42
46
```
43
47
44
-
### Exercise 1: Introduction
48
+
### Exercise 1: Write a GET Request
45
49
46
50
For this exercise we will be adding a new endpoint to handle a simple GET request.
47
51
48
52
- Move to the `src/main/.../DemoController.java` file
49
-
- Start writing the code to handle a simple GET request based on the javadoc comment. Just press enter and wait a couple of seconds, Copilot will generate the code for you.
53
+
- Start writing the code to handle a simple GET request based on the javadoc comment.
54
+
- Just press enter and wait a couple of seconds, Copilot will generate the code for you.
50
55
- Alternatively, you can test the Copilot inline feature by pressing `ctrl/⌘ + i`. Then write in the text box the desired behaviour.
56
+
57
+
You can now run the application and then test it with curl.
58
+
59
+
1. Run the spring app: `./mvnw spring-boot:run`
60
+
2. Test with curl: `curl -v http://localhost:8080/hello?key=world`
61
+
3. If you are using GitHub `Codespaces`, replace localhost:8080 with actual `Codespaces` url.
62
+
63
+
64
+
### Exercise 2: Write a Test Case
65
+
66
+
There is an existing unit test `src/test/.../CopilotDemoApplicationTests.java`, run below command to test it.
67
+
51
68
- run `./mvnw test`
52
69
- If the test passed you should see something like this:
53
70
@@ -66,11 +83,6 @@ For this exercise we will be adding a new endpoint to handle a simple GET reques
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`
107
+
### Exercise 3: Building more functionalities
98
108
99
-
Add the following endpoints using the help of Copilot.
109
+
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`.
100
110
101
-
Additionally, create a unit test that validates the operation.
102
-
103
-
From now on, you will have to create the unit tests for every new operation. Wasn't it easy with Copilot?
111
+
Add the following endpoints using the help of Copilot, then also create the unit tests for every new operation. It is pretty easy with Copilot !
104
112
105
113
-**/daysbetweendates**:
106
114
@@ -140,6 +148,12 @@ From now on, you will have to create the unit tests for every new operation. Was
140
148
> Paste the above information and make it as detailed as possible in the Copilot chat text box.
141
149
> Copilot will use by default the open file as context in order to generate the suggestion.
142
150
151
+
152
+
### Exercise 4: Building more integrations
153
+
154
+
We have tried out write coding for a few simple tasks earlier. Now let's explore more complex integrations.
155
+
156
+
143
157
-**/tellmeajoke**:
144
158
145
159
- Make a call to the joke api and return a random joke - <https://api.chucknorris.io/jokes/random>
@@ -183,19 +197,21 @@ From now on, you will have to create the unit tests for every new operation. Was
183
197
- Return a random country from the array
184
198
- Return the country and its iso code
185
199
186
-
### Exercise 3: Document the code
200
+
### Exercise 5: Document the code
187
201
188
202
Documenting code is always a boring and painful task. However, we can use Copilot to document it for us. In the chat, ask Copilot to add javadoc to all of your files.
189
203
190
-
### Exercise 4: Verify Tests
204
+
You can use `@workspaces` to write documentation for the whole repo.
205
+
206
+
### Exercise 6: Verify Tests
191
207
192
208
Have you been building your Unit Tests along the way? If not this is the perfect time to take a breather and get Copilot to write some unit tests for you!
193
209
194
210
We will create automated tests to check that the functionality of the previous endpoints is correctly implemented. The tests should be together in the `CopilotDemoApplicationTests.java` file.
195
211
196
212
You can leverage Copilot to run the tests. There is a `/tests` command that you can directly run from Copilot Chat or by selecting the piece of code you want to create tests for and using the Copilot inline feature.
197
213
198
-
### Exercise 5: Create a Dockerfile
214
+
### Exercise 7: Create a Dockerfile
199
215
200
216
Use the Dockerfile provided to create a docker image of the application. There are some comments in the Dockerfile that will help you to complete the exercise.
0 commit comments