From the course: Software Testing Assistance with GitHub Copilot AI

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Write your tests to document business logic

Write your tests to document business logic

- [Instructor] While automated testing is a step to limiting risk and preventing regressions, another major value is documenting the intent of business logic directly in your code base. I'm going to continue working with redirect logic. Here, I have existing logic and I could highlight some parts of it and ask co-pilot to generate tests. Instead, another wrinkle is to document code intent via tests. First, I'll create a new empty test function. And the first method I'll create is to capture the intended logic. This method is basic redirection, and in there I'll add a comment to indicate what I'm trying to test for. In this case, I'm testing that certain keywords always redirect to an external site. Now I'm using PHP unit, which is unit testing. I don't have a test library to make a remote get request and observe the header response. That's okay because I can test the should redirect and redirect value logic. So I add a new method. Test should redirect. And because it's a bool copilot…

Contents