Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

UTBot Go

About project

UTBot Go automatically generates unit tests for Go programs. Generated tests:

  • provide high code coverage and, as a result, its reliability;
  • fixate the current behavior of the code as regression tests.

The core principles of UTBot Go are ease of use and maximizing code coverage.


The project is currently under development.

Features

At the moment, only the basic fuzzing technique is supported: namely, the execution of functions on predefined values, depending on the type of parameter.

At the moment, functions are supported, the parameters of which have any primitive types, namely:

  • bool
  • int, int8, int16, int32, int64
  • uint, uint8, uint16, uint32, uint64
  • byte, rune, string
  • float64, float32
  • complex128, complex64
  • uintptr

For floating point types, correct work with infinities and NaNs is also supported.

Function result types are supported the same as for parameters, but with support for types that implement error.

In addition, UTBot Go correctly captures not only errors returned by functions, but also panic cases.

Examples of supported functions can be found here.

Install and use easily

IntelliJ IDEA plugin

Requirements:

  • IntelliJ IDEA (Ultimate Edition), compatible with version 2022.1;
  • installed Go SDK version compatible with 1.19 or 1.18;
  • installed in IntelliJ IDEA Go plugin, compatible with the IDE version (it is for this that the Ultimate edition of the IDE is needed);
  • properly configured Go module for source code file (i.e. for file to generate tests for): corresponding go.mod file must exist.

Most likely, if you are already developing Go project in IntelliJ IDEA, then you have already met all the requirements.

To install the UTBot Go plugin in IntelliJ IDEA:

  • just find the latest version of UnitTestBot in the plugin market;
  • or download zip archive with utbot-intellij JAR from here and install it in IntelliJ IDEA as follows from plugins section (yes, you need to select the entire downloaded zip archive, it does not need to be unpacked).

Finally, you can start using UTBot Go: open any .go file in the IDE and press alt + u, alt + t. After that, a window will appear in which you can configure the test generation settings and start running it in a couple of clicks.

CLI application

Requirements:

  • installed Java SDK version 11 or higher;
  • installed Go SDK version compatible with 1.19 or 1.18;
  • properly configured Go module for source code file (i.e. for file to generate tests for): corresponding go.mod file must exist.

To install the UTBot Go CLI application: download zip archive containing utbot-cli JAR from here, then extract its content (JAR file) to a convenient location.

Finally, you can start using UTBot Go by running the extracted JAR on the command line. For example, to find out about all flags of UTBot Go CLI application, run the command as follows (utbot-cli-2022.8-beta.jar here is the path to the extracted JAR).

java -jar utbot-cli-2022.8-beta.jar generateGo --help

UTBot Go CLI application options:

  • -s, --source TEXT, required: specifies Go source file to generate tests for.
  • -f, --function TEXT: specifies function name to generate tests for. Can be used multiple times to select multiple functions at the same time. If no functions are specified, all functions contained in the source file are selected.
  • -g, --go-path TEXT, required: specifies path to Go executable. For example, it could be /usr/local/go/bin/go for some systems.
  • -p, --print-test: specifies whether a test should be printed out to StdOut.
  • -w, --overwrite: specifies whether to overwrite the output test file if it already exists.
  • -h, --help: show help message and exit.

Contribute to UTBot Go

If you want to take part in the development of the project or learn more about how it works, check out DEVELOPERS_GUIDE.md.

For the current list of tasks, check out FUTURE_PLANS.md.

Your help and interest is greatly appreciated!