This is the third post in our Chatbot Chronicles series.

As a development agency, we understand that ensuring code quality and reducing errors is crucial to the success of any software development project. At Sauce, we've leveraged the power of artificial intelligence to improve our code quality and reduce errors through code reviews and writing unit tests.

In my previous post, I wrote about using Chat-GPT as a pair programmer for general day-to-day development. In this post, I'd like to focus on two essential aspects of development: code reviews and writing tests.

Code Reviews

At Sauce, we've incorporated code reviews into our workflow since our founding over seven years ago. Every line of code must be reviewed by at least one other team member before it can be merged into production. While this is a standard industry practice that helps improve code quality and reduce bugs, it's not without its drawbacks. Developers need to switch context and take the time to conduct a thorough code review, and junior developers reviewing senior code can feel uncomfortable questioning commits.

While we don't believe that manual human code reviews will go away anytime soon, we have found success in asking Chat-GPT to review small functionality and suggest refinements. While it's not currently possible to provide Chat-GPT with the context of a large codebase, there are solutions available that are working on this, such as GitGuardian and Bloop.ai.

Here’s a simple example to demonstrate. What’s really great is that it runs through the feedback line by line. This is great for developers who are learning a new language or framework. It gives them an opportunity to learn new techniques and their application. Interestingly it will also respond with different code each time.

Unit Tests

The other critical aspect of maintaining great software is writing tests. However, many developers dislike this task, and it can often be more challenging to write a good test than the function itself. Good test coverage is essential for the long-term success of an application, as it cuts down on future bugs where different developers may be working on a project unaware of the side effects their changes will have.

At Sauce, we've had great success writing unit tests by giving Chat-GPT the function and asking it to write a unit test. The developer can then adapt the unit test with their parameters or specify them to the bot to update the test.

Let’s pickup that previous refactored code and ask it to write a unit test. This was for a utility function in an EmberJS framework, so I’ll make sure to include this context in the question.

Just amazing! Because I told it I was working in the EmberJS framework it formatted the test code correctly using qUnit and even guessed correctly that my function was a utility!

Whats Next?

We believe that the use of artificial intelligence in software development will become increasingly common, and we're excited to stay at the forefront of this technological advancement. By incorporating AI into our code review and unit testing workflows, we've been able to improve code quality and reduce errors. At Sauce, we're committed to leveraging AI to deliver exceptional software solutions to our clients.