Automating Unit tests

Within this experiment a generic open-source model for generating code was created to avoid the repetitiveness of writing unit tests manually. This makes this use case ideal for automation. In the first example two methods for generating unit tests are presented. We will provide one full example and write down the name of the second method that we expect you to supplemented.

1.1 Input

1.2 Output

When we look at the output, we see that the model chooses the correct method, and then also understands that the outcome should not be equal to the previous example, but zero instead of twenty.

Let’s try it without an example, with just the code as input and the start of a test case.

2.1 Input

Here some comments have already been added to the output:

We see that the correct skeleton is generated. The language model clearly understands the given code and the concept of unit tests, the first two are even completely correct.

In case that you are interested in the original code:

So we see that using language models is certainly an option as a pair programmer. You can go for commercial options like GitHub Copilot or simply paste a piece of code into Eleuther (open source, free). Earlier we also saw that GPT-3 is able to create  a simple game, so why not delegate your repetitive use cases to an AI?

This article belongs to the following project:

AI in Production

Artificial Intelligence (AI) is a buzzword that has become hard to ignore lately. Despite much attention to the subject at...

IMAGE GALLERY