Auto unit test writing?

Hello fellow Gophers !

Is there any software that scans a .go file, identifies public methods, then writes unit tests for it ?

I have found two, but both have a huge disadvantage:


Both of them scan a file, and write unit test stubs.

While this is very good, I am looking for a step forward: look at the parameters of a public method, randomly generate some N such parameter combinations and call that method, with them, N times.

Finally, write N unit tests that for those N parameter combinations expect whatever the method returned these recently ran N times.

These tests with random data, will form a battery of unit tests, that guard against wrong refactoring. Does such a software exist ? Any advice on this is welcomed.

I’m skeptical this would work well in general. Sure there are some mathematical pure functions that behave like that and could be tested in this way. However many other functions take interfaces and complex types like database connections, sockets, templates, … Autogenerating random code for these isn’t going to result in something working.

database connections, sockets, templates - these are not pure functions. I have no expectations for its to work.

This test idea only needs ot work on pure function (no external parameters, random, system calls) and simple numeric/string parameters.

Even so I doubt it would be valuable. Take for example strings.Split which is a super simple such function - an input string and a separator. Five calls with random strings for both will say nothing useful about the behavior.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.