I like to write a quality software, but I do not like to write tests. This work is boring and repetitive.

What is tests in general - this is a check of instructions that we have in code.

Would it be nice to have a tool that will generate test instruction for us? Welcome, TestGen AI! This tool write tests for us.

TestGen AI Logo
TestGen AI Logo

Disclaimer: This article is based on my experience and I did not receive any compensation from the author of this tool.

Get +2% code coverage?

Here is my short story. I’m a maintainer of a small open source project ElementFinder. I like when my coverage is close to 100%. So I started to test this tool with my project.

I have a class StringCollection that has a method last. This class is like a generic implementation for List<String>. Unfortunately in PHP we do not have generics (2023y), we write more code than usual :(.

Anyway, I checked the current coverage of this class, and it was 93%.

Start point. Code coverage 93%.
Start point. Code coverage 93%.

In our last method one line is not covered. It is a simple return null; statement. Let’s check how AI can help us here. I pasted the content of the class to the TestGen AI.

A few seconds later I got a result. Here is the autogenerated test.

Autogenerated tests
Autogenerated tests

Just by looking into test data you can guess that our return null should be covered. Let’s check it.

Code coverage 100%
Code coverage 100%

As you can see, AI helped us to cover this line. CMD+C, CMD+V, and we have a new test.

Pros and Cons

This tool is cool. It is easy to use, and it can help you to write tests faster. But it is not perfect. For OSS project it can be easily used (You are the owner and the code is public), but for private projects it can be a problem. Security compliance can be a stop signal here. Especially with AI and all this stuff it is hard to explain to the security team what is the data flow and in what way we can leak the code.

The future of Testing

I think that in the future, we will have more tools like this. Integrations will be smooth and easy. We’ll use tools that cover the whole classes in seconds. Humans become reviewers of the tests, and not writers.

Conclusion

  • explode
  • play with new tools
  • create OSS projects
  • improve code quality