Skip to content

Errorf not finishes test execution #150

Closed
@DifferentialOrange

Description

@DifferentialOrange

We use t.Errorf in tests, for example

t.Errorf("Failed to connect: %s", err.Error())

It seems that by design t.Errorf do not stops test function execution, but it is expected in tests:

package main

import (
	"testing"
)

func TestEverything(t *testing.T) {
	a := "sdf"
	if a == "sdf" {
		t.Errorf("end")
	}
	t.Errorf("end 2")
}
=== RUN   TestEverything
    prog.go:10: end
    prog.go:12: end 2
--- FAIL: TestEverything (0.00s)
FAIL

Program exited.

Documentation says:

Errorf is equivalent to Logf followed by Fail.
Fail marks the function as having failed but continues execution.

We should use Fatalf(doc) or explicit returns where it's expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcode healthImprove code readability, simplify maintenance and so on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions