📖 5 min read (~ 900 words).

Boolean

Asserting Boolean Values

Assertions

GoDoc

All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2

This domain exposes 4 functionalities. Generic assertions are marked with a .

False

False asserts that the specified value is false.

Examples
	assertions.False(t, myBool)
	success: 1 == 0
	failure: 1 == 1
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestFalse(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestFalse(t *testing.T)
    	success := assert.False(t, 1 == 0)
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestFalse(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestFalse(t *testing.T)
    	require.False(t, 1 == 0)
    	fmt.Println("passed")
    
    }

FalseT[B Boolean]

FalseT asserts that the specified value is false.

The type constraint Boolean accepts any type which underlying type is bool.

Examples
	type B bool
	var b B = true
	assertions.FalseT(t, b)
	success: 1 == 0
	failure: 1 == 1
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestFalseT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestFalseT(t *testing.T)
    	success := assert.FalseT(t, 1 == 0)
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestFalseT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestFalseT(t *testing.T)
    	require.FalseT(t, 1 == 0)
    	fmt.Println("passed")
    
    }

True

True asserts that the specified value is true.

Examples
	assertions.True(t, myBool)
	success: 1 == 1
	failure: 1 == 0
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestTrue(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestTrue(t *testing.T)
    	success := assert.True(t, 1 == 1)
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestTrue(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestTrue(t *testing.T)
    	require.True(t, 1 == 1)
    	fmt.Println("passed")
    
    }

TrueT[B Boolean]

TrueT asserts that the specified value is true.

The type constraint Boolean accepts any type which underlying type is bool.

Examples
	type B bool
	var b B = true
	assertions.True(t, b)
	success: 1 == 1
	failure: 1 == 0
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestTrueT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestTrueT(t *testing.T)
    	success := assert.TrueT(t, 1 == 1)
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestTrueT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestTrueT(t *testing.T)
    	require.TrueT(t, 1 == 1)
    	fmt.Println("passed")
    
    }


Generated with github.com/go-openapi/testify/codegen/v2