File tree Expand file tree Collapse file tree 4 files changed +10
-14
lines changed
main/java/com/microsoft/hackathon/copilotdemo/controller
test/java/com/microsoft/hackathon/copilotdemo Expand file tree Collapse file tree 4 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ Please run the following to give it execute permissions.
4545chmod +x ./mvnw
4646```
4747
48- ### Exercise 1: Write a GET Request
48+ ### Exercise 1: Write a "Hello world" GET Request
4949
5050For this exercise we will be adding a new endpoint to handle a simple GET request.
5151
@@ -60,10 +60,12 @@ You can now run the application and then test it with curl.
60602 . Test with curl: ` curl -v http://localhost:8080/hello?key=world `
61613 . If you are using GitHub ` Codespaces ` , replace localhost:8080 with actual ` Codespaces ` url.
6262
63- ### Exercise 2: Write a Test Case
63+ ### Exercise 2: Write a "Hello world" Test Case
6464
65- There is an existing unit test ` src/test/.../CopilotDemoApplicationTests.java ` , run below command to test it .
65+ Navigate to ` src/test/.../CopilotDemoApplicationTests.java ` , to start writing your first test .
6666
67+ - Just press enter and wait a couple of seconds, Copilot will generate the code for you.
68+ - Alternatively, you can test the Copilot inline feature by pressing ` ctrl/⌘ + i ` . Then write in the text box the desired behaviour.
6769- run ` ./mvnw test `
6870- If the test passed you should see something like this:
6971
Original file line number Diff line number Diff line change 55import org .springframework .web .bind .annotation .RestController ;
66
77/*
8- * Create a GET operation to return the value of a key passed as query parameter.
8+ * Create a /hello GET operation to return the value of a key passed as query parameter.
99* If the key is not passed, return "key not passed".
1010* If the key is passed, return "hello <key>".
1111*
Original file line number Diff line number Diff line change 88import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
99import org .springframework .test .web .servlet .result .MockMvcResultMatchers ;;
1010
11-
1211@ SpringBootTest ()
13- @ AutoConfigureMockMvc
12+ @ AutoConfigureMockMvc
1413class CopilotDemoApplicationTests {
1514
16- @ Autowired
17- private MockMvc mockMvc ;
15+ @ Autowired
16+ private MockMvc mockMvc ;
1817
19- @ Test
20- void hello () throws Exception {
21- mockMvc .perform (MockMvcRequestBuilders .get ("/hello?key=world" ))
22- .andExpect (MockMvcResultMatchers .status ().isOk ())
23- .andExpect (MockMvcResultMatchers .content ().string ("hello world" ));
24- }
18+ // Create a test to check if the /hello GET operation that accepts key as query parameter and returns "hello <key>" is working correctly.
2519
2620}
You can’t perform that action at this time.
0 commit comments