Skip to content

Go tests are not generated when imports are needed for types inside a function body #1776

Description

@egiptipavel

Description

Tests are not generated if there are types in the function body that are not among the parameters, result parameters of the function and the following list of imports: "io", "context", "encoding/json", "errors", "fmt", "log", "math", "net", "reflect", "strconv", "strings", "testing", "time", "unsafe".

To Reproduce

Steps to reproduce the behavior:

  1. Write the following function:
import "math/cmplx"

func Abs(n complex128) float64 {
	return cmplx.Abs(n)
}
  1. Use plugin to generate tests

Expected behavior

Similar to this file should be generated.

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestAbsByUtGoFuzzer(t *testing.T) {
	actualVal := Abs(complex(1.0, 1.0))

	assert.Equal(t, 1.4142135623730951, actualVal)
}

Actual behavior

Empty file is generated.

Visual proofs (screenshots, logs, images)

| UtBot - GoTestCasesGenerator      | Fuzzing for function [Abs] - started
| UtBot - GoTestCasesGenerator      | Error in flow: Timeout exceeded: Worker not connected. Process output: # simple [simple.test]
.\utbot_go_worker_samples_test.go:637:9: undefined: cmplx
FAIL	simple [build failed]

| UtBot - GoTestCasesGenerator      | Fuzzing for function [Abs] - completed in 10027 ms. Generated 0 test cases

Environment

There is no specific environment.

Additional context

There is no additional context.

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a buglang-goIssue is related to Go support

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions