Now you've had an opportunity to get started using GitHub Copilot, we have a number of challenges for you to attempt. Remember the goal here is not to test your programming abilities but rather, see how you can use GitHub Copilot to help you complete these tasks. Even if you're not a developer, you may be surprised how Copilot can help you be successful with these challenge.
Challenge #1 - Adding Unit Tests
-
Press
CTRL + `
to open the terminal window in VS Code if it is not already open. -
Enter
npm test
in the terminal window and press ENTER to execute the existing unit tests for the Calculator application. -
Scroll up in the terminal window to see what tests have been executed. You should see tests for Arithmetic validation, Addition, Multiplication and Division. There are no tests for the subtraction function!
-
Open the
/test/arithmetic.test.js
file. -
Scroll down to the line with the comment
TODO: Challenge #1
(Around line 96) -
On the line following the comment, add a new comment to provide context to GitHub Copilot on what you want assistance to do. Try adding this comment
// add tests for subtraction
and pressENTER
to generate a suggestion. -
Accept the suggested line if it looks right by pressing
TAB
thenENTER
. -
Continue accepting suggestions line by line to see how many unit tests you can have Copiloit assist you in writing.
-
Once you're happy with a few unit tests, save the file and return to the terminal window. Enter
npm test
and press ENTER to execute the unit tests again.
NOTE: The advanced features currently available in GitHub CopilotX Chat, provide far more sophisticated assistance in writing unit tests, including the ability to write complete test suites for you. At the time of creating this exercise, Copilot Chat was only available as a pre-release experiment.
Challenge #2 - Adding Unit Tests for the power/exponential function
- See if you can now add additional unit tests for the power/exponential function you created in the core exercise.
Challenge #3 - Adding a new function
-
See if you can now add an entirely new function to the calculator using GitHub Copilot to assist you. The previous exercises will help you locate where you want to add code.
-
Once your function is working, consider adding the necessary unit tests to confirm it's functionality.
Once you've completed the challenges, you may like to review the additional resources