6 Testing and prompt engineering
This chapter covers
- Understanding the importance of testing Copilot code
- Using closed-box versus open-box testing
- Addressing errors by Copilot by modifying prompts
- Viewing examples of testing code produced by Copilot
In chapter 3, we first started to see the importance of testing the code produced by Copilot. Testing is an essential skill for anyone writing software because it gives you confidence that the code is functioning properly. In this chapter, we’ll learn how to test our code thoroughly and how to help Copilot fix code that doesn’t work by modifying our prompts.
6.1 Why it is crucial to test code
Back in chapter 3, we mentioned that you should test code to make sure it is correct. Unfortunately, we’ve seen student after student be reluctant to test. Why? We think a couple of things are at play. The first is that there’s this well-documented problem nicknamed the Superbug, which is that humans, when first learning to code, think the computer can understand the intent of the code and respond accordingly [1]. Since they wrote the code and the code made sense to them, of course it should work. The second problem is compounded on the first: if you think your code is right, testing can only bring you bad news. If you don’t test, you can’t find out if the code is wrong. It’s like the old saying about putting your head in the sand.