Creating unit tests: is the glass half empty or half full

You can ask ChatGPT to create unit tests for a class. Just paste the class code into the prompt and ask it to create unit test.

It will then create a good start for a unit test that will fail 100%. ChatGPT 4 does understand the concept of a unit test. It understands what to test for a class that has this and that member and this and that method. Not perfectly well but usable as a great starting point.

However, ChatGPT is no human who understands what the class is supposed to do. It is a large language model and it tries to make sense of the class in terms of the words you're using for members and such, often with hilariously wrong test data.

I still find it useful, it generates all the right method calls and correct syntax and even descriptions what the test does. All you need to do is to change what the test data you feed in and result really should be.

So for me the glass is half full. ChatGPT makes my writing unit tests faster by maybe a factor of 2.


Kommentare

Beliebte Posts aus diesem Blog

ChatGPT as a teacher

How it started...

Pathfinding and A*