📖 23 min read (~ 4900 words).

Collection

Asserting Slices And Maps

Assertions

GoDoc

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

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

Contains

Contains asserts that the specified string, list(array, slice…) or map contains the specified substring or element.

Examples
	assertions.Contains(t, "Hello World", "World")
	assertions.Contains(t, []string{"Hello", "World"}, "World")
	assertions.Contains(t, map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"Hello": "World"}, "Hello")
	success: []string{"A","B"}, "A"
	failure: []string{"A","B"}, "C"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestContains(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 TestContains(t *testing.T)
    	success := assert.Contains(t, []string{"A", "B"}, "A")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestContains(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 TestContains(t *testing.T)
    	require.Contains(t, []string{"A", "B"}, "A")
    	fmt.Println("passed")
    
    }

ElementsMatch

ElementsMatch asserts that the specified listA(array, slice…) is equal to specified listB(array, slice…) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.

Examples
	assertions.ElementsMatch(t, []int{1, 3, 2, 3}, []int{1, 3, 3, 2})
	success: []int{1, 3, 2, 3}, []int{1, 3, 3, 2}
	failure: []int{1, 2, 3}, []int{1, 2, 4}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestElementsMatch(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 TestElementsMatch(t *testing.T)
    	success := assert.ElementsMatch(t, []int{1, 3, 2, 3}, []int{1, 3, 3, 2})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestElementsMatch(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 TestElementsMatch(t *testing.T)
    	require.ElementsMatch(t, []int{1, 3, 2, 3}, []int{1, 3, 3, 2})
    	fmt.Println("passed")
    
    }

ElementsMatchT[E comparable]

ElementsMatchT asserts that the specified listA(array, slice…) is equal to specified listB(array, slice…) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.

Examples
	assertions.ElementsMatchT(t, []int{1, 3, 2, 3}, []int{1, 3, 3, 2})
	success: []int{1, 3, 2, 3}, []int{1, 3, 3, 2}
	failure: []int{1, 2, 3}, []int{1, 2, 4}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestElementsMatchT(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 TestElementsMatchT(t *testing.T)
    	success := assert.ElementsMatchT(t, []int{1, 3, 2, 3}, []int{1, 3, 3, 2})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestElementsMatchT(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 TestElementsMatchT(t *testing.T)
    	require.ElementsMatchT(t, []int{1, 3, 2, 3}, []int{1, 3, 3, 2})
    	fmt.Println("passed")
    
    }

Len

Len asserts that the specified object has specific length.

Len also fails if the object has a type that len() does not accept.

The asserted object can be a string, a slice, a map, an array, pointer to array or a channel.

Examples
	assertions.Len(t, mySlice, 3)
	assertions.Len(t, myString, 4)
	assertions.Len(t, myMap, 5)
	success: []string{"A","B"}, 2
	failure: []string{"A","B"}, 1
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestLen(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 TestLen(t *testing.T)
    	success := assert.Len(t, []string{"A", "B"}, 2)
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestLen(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 TestLen(t *testing.T)
    	require.Len(t, []string{"A", "B"}, 2)
    	fmt.Println("passed")
    
    }

MapContainsT[Map ~map[K]V, K comparable, V any]

MapContainsT asserts that the specified map contains a key.

Go native comparable types are explained there: comparable-types.

Examples
	assertions.MapContainsT(t, map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"Hello": "x","World": "y"}, "World")
	success: map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"A": "B"}, "A"
	failure: map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"A": "B"}, "C"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestMapContainsT(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 TestMapContainsT(t *testing.T)
    	success := assert.MapContainsT(t, map[string]string{"A": "B"}, "A")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestMapContainsT(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 TestMapContainsT(t *testing.T)
    	require.MapContainsT(t, map[string]string{"A": "B"}, "A")
    	fmt.Println("passed")
    
    }

MapNotContainsT[Map ~map[K]V, K comparable, V any]

MapNotContainsT asserts that the specified map does not contain a key.

Examples
	assertions.MapNotContainsT(t, map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"Hello": "x","World": "y"}, "hi")
	success: map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"A": "B"}, "C"
	failure: map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)string{"A": "B"}, "A"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestMapNotContainsT(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 TestMapNotContainsT(t *testing.T)
    	success := assert.MapNotContainsT(t, map[string]string{"A": "B"}, "C")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestMapNotContainsT(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 TestMapNotContainsT(t *testing.T)
    	require.MapNotContainsT(t, map[string]string{"A": "B"}, "C")
    	fmt.Println("passed")
    
    }

NotContains

NotContains asserts that the specified string, list(array, slice…) or map does NOT contain the specified substring or element.

Examples
	assertions.NotContains(t, "Hello World", "Earth")
	assertions.NotContains(t, ["Hello", "World"], "Earth")
	assertions.NotContains(t, {"Hello": "World"}, "Earth")
	success: []string{"A","B"}, "C"
	failure: []string{"A","B"}, "B"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotContains(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 TestNotContains(t *testing.T)
    	success := assert.NotContains(t, []string{"A", "B"}, "C")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotContains(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 TestNotContains(t *testing.T)
    	require.NotContains(t, []string{"A", "B"}, "C")
    	fmt.Println("passed")
    
    }

NotElementsMatch

NotElementsMatch asserts that the specified listA(array, slice…) is NOT equal to specified listB(array, slice…) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should not match. This is an inverse of ElementsMatch.

Examples
	assertions.NotElementsMatch(t, []int{1, 1, 2, 3}, []int{1, 1, 2, 3}) -> false
	assertions.NotElementsMatch(t, []int{1, 1, 2, 3}, []int{1, 2, 3}) -> true
	assertions.NotElementsMatch(t, []int{1, 2, 3}, []int{1, 2, 4}) -> true
	success: []int{1, 2, 3}, []int{1, 2, 4}
	failure: []int{1, 3, 2, 3}, []int{1, 3, 3, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotElementsMatch(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 TestNotElementsMatch(t *testing.T)
    	success := assert.NotElementsMatch(t, []int{1, 2, 3}, []int{1, 2, 4})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotElementsMatch(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 TestNotElementsMatch(t *testing.T)
    	require.NotElementsMatch(t, []int{1, 2, 3}, []int{1, 2, 4})
    	fmt.Println("passed")
    
    }

NotElementsMatchT[E comparable]

NotElementsMatchT asserts that the specified listA(array, slice…) is NOT equal to specified listB(array, slice…) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should not match. This is an inverse of ElementsMatch.

Examples
	assertions.NotElementsMatchT(t, []int{1, 1, 2, 3}, []int{1, 1, 2, 3}) -> false
	assertions.NotElementsMatchT(t, []int{1, 1, 2, 3}, []int{1, 2, 3}) -> true
	assertions.NotElementsMatchT(t, []int{1, 2, 3}, []int{1, 2, 4}) -> true
	success: []int{1, 2, 3}, []int{1, 2, 4}
	failure: []int{1, 3, 2, 3}, []int{1, 3, 3, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotElementsMatchT(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 TestNotElementsMatchT(t *testing.T)
    	success := assert.NotElementsMatchT(t, []int{1, 2, 3}, []int{1, 2, 4})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotElementsMatchT(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 TestNotElementsMatchT(t *testing.T)
    	require.NotElementsMatchT(t, []int{1, 2, 3}, []int{1, 2, 4})
    	fmt.Println("passed")
    
    }

NotSubset

NotSubset asserts that the list (array, slice, or map) does NOT contain all elements given in the subset (array, slice, or map). Map elements are key-value pairs unless compared with an array or slice where only the map key is evaluated.

Examples
	assertions.NotSubset(t, [1, 3, 4], [1, 2])
	assertions.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
	assertions.NotSubset(t, [1, 3, 4], {1: "one", 2: "two"})
	assertions.NotSubset(t, {"x": 1, "y": 2}, ["z"])
	success: []int{1, 2, 3}, []int{4, 5}
	failure: []int{1, 2, 3}, []int{1, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotSubset(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 TestNotSubset(t *testing.T)
    	success := assert.NotSubset(t, []int{1, 2, 3}, []int{4, 5})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestNotSubset(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 TestNotSubset(t *testing.T)
    	require.NotSubset(t, []int{1, 2, 3}, []int{4, 5})
    	fmt.Println("passed")
    
    }

SeqContainsT[E comparable]

SeqContainsT asserts that the specified iterator contains a comparable element.

The sequence may not be consumed entirely: the iteration stops as soon as the specified element is found.

Go native comparable types are explained there: comparable-types.

Examples
	assertions.SeqContainsT(t, slices.Values([]{"Hello","World"}), "World")
	success: slices.Values([]string{"A","B"}), "A"
	failure: slices.Values([]string{"A","B"}), "C"
  • Copy and click to open Go Playground

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

    // real-world test would inject *testing.T from TestSeqContainsT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"slices"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestSeqContainsT(t *testing.T)
    	require.SeqContainsT(t, slices.Values([]string{"A", "B"}), "A")
    	fmt.Println("passed")
    
    }

SeqNotContainsT[E comparable]

SeqNotContainsT asserts that the specified iterator does not contain a comparable element.

See SeqContainsT.

Examples
	assertions.SeqContainsT(t, slices.Values([]{"Hello","World"}), "World")
	success: slices.Values([]string{"A","B"}), "C"
	failure: slices.Values([]string{"A","B"}), "A"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSeqNotContainsT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"slices"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/assert"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestSeqNotContainsT(t *testing.T)
    	success := assert.SeqNotContainsT(t, slices.Values([]string{"A", "B"}), "C")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSeqNotContainsT(t *testing.T)
    package main
    
    import (
    	"fmt"
    	"slices"
    	"testing"
    
    	"github.com/go-openapi/testify/v2/require"
    )
    
    func main() {
    	t := new(testing.T) // should come from testing, e.g. func TestSeqNotContainsT(t *testing.T)
    	require.SeqNotContainsT(t, slices.Values([]string{"A", "B"}), "C")
    	fmt.Println("passed")
    
    }

SliceContainsT[Slice ~[]E, E comparable]

SliceContainsT asserts that the specified slice contains a comparable element.

Go native comparable types are explained there: comparable-types.

Examples
	assertions.SliceContainsT(t, []{"Hello","World"}, "World")
	success: []string{"A","B"}, "A"
	failure: []string{"A","B"}, "C"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceContainsT(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 TestSliceContainsT(t *testing.T)
    	success := assert.SliceContainsT(t, []string{"A", "B"}, "A")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceContainsT(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 TestSliceContainsT(t *testing.T)
    	require.SliceContainsT(t, []string{"A", "B"}, "A")
    	fmt.Println("passed")
    
    }

SliceNotContainsT[Slice ~[]E, E comparable]

SliceNotContainsT asserts that the specified slice does not contain a comparable element.

See SliceContainsT.

Examples
	assertions.SliceNotContainsT(t, []{"Hello","World"}, "hi")
	success: []string{"A","B"}, "C"
	failure: []string{"A","B"}, "A"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceNotContainsT(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 TestSliceNotContainsT(t *testing.T)
    	success := assert.SliceNotContainsT(t, []string{"A", "B"}, "C")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceNotContainsT(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 TestSliceNotContainsT(t *testing.T)
    	require.SliceNotContainsT(t, []string{"A", "B"}, "C")
    	fmt.Println("passed")
    
    }

SliceNotSubsetT[Slice ~[]E, E comparable]

SliceNotSubsetT asserts that a slice of comparable elements does not contain all the elements given in the subset.

Examples
	assertions.SliceNotSubsetT(t, []int{1, 2, 3}, []int{1, 4})
	success: []int{1, 2, 3}, []int{4, 5}
	failure: []int{1, 2, 3}, []int{1, 2}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceNotSubsetT(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 TestSliceNotSubsetT(t *testing.T)
    	success := assert.SliceNotSubsetT(t, []int{1, 2, 3}, []int{4, 5})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceNotSubsetT(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 TestSliceNotSubsetT(t *testing.T)
    	require.SliceNotSubsetT(t, []int{1, 2, 3}, []int{4, 5})
    	fmt.Println("passed")
    
    }

SliceSubsetT[Slice ~[]E, E comparable]

SliceSubsetT asserts that a slice of comparable elements contains all the elements given in the subset.

Examples
	assertions.SliceSubsetT(t, []int{1, 2, 3}, []int{1, 2})
	success: []int{1, 2, 3}, []int{1, 2}
	failure: []int{1, 2, 3}, []int{4, 5}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceSubsetT(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 TestSliceSubsetT(t *testing.T)
    	success := assert.SliceSubsetT(t, []int{1, 2, 3}, []int{1, 2})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSliceSubsetT(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 TestSliceSubsetT(t *testing.T)
    	require.SliceSubsetT(t, []int{1, 2, 3}, []int{1, 2})
    	fmt.Println("passed")
    
    }

StringContainsT[ADoc, EDoc Text]

StringContainsT asserts that a string contains the specified substring.

Strings may be go strings or []byte according to the type constraint Text.

Examples
	assertions.StringContainsT(t, "Hello World", "World")
	success: "AB", "A"
	failure: "AB", "C"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestStringContainsT(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 TestStringContainsT(t *testing.T)
    	success := assert.StringContainsT(t, "AB", "A")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestStringContainsT(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 TestStringContainsT(t *testing.T)
    	require.StringContainsT(t, "AB", "A")
    	fmt.Println("passed")
    
    }

StringNotContainsT[ADoc, EDoc Text]

StringNotContainsT asserts that a string does not contain the specified substring.

See StringContainsT.

Examples
	assertions.StringNotContainsT(t, "Hello World", "hi")
	success: "AB", "C"
	failure: "AB", "A"
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestStringNotContainsT(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 TestStringNotContainsT(t *testing.T)
    	success := assert.StringNotContainsT(t, "AB", "C")
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestStringNotContainsT(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 TestStringNotContainsT(t *testing.T)
    	require.StringNotContainsT(t, "AB", "C")
    	fmt.Println("passed")
    
    }

Subset

Subset asserts that the list (array, slice, or map) contains all elements given in the subset (array, slice, or map).

Map elements are key-value pairs unless compared with an array or slice where only the map key is evaluated.

nil values are considered as empty sets.

Examples
	assertions.Subset(t, []int{1, 2, 3}, []int{1, 2})
	assertions.Subset(t, []string{"x": 1, "y": 2}, []string{"x": 1})
	assertions.Subset(t, []int{1, 2, 3}, map[int](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#int)string{1: "one", 2: "two"})
	assertions.Subset(t, map[string](https://pkg.go.dev/github.com/go-openapi/testify/v2/assert#string)int{"x": 1, "y": 2}, []string{"x"})
	success: []int{1, 2, 3}, []int{1, 2}
	failure: []int{1, 2, 3}, []int{4, 5}
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSubset(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 TestSubset(t *testing.T)
    	success := assert.Subset(t, []int{1, 2, 3}, []int{1, 2})
    	fmt.Printf("success: %t\n", success)
    
    }
  • Copy and click to open Go Playground

    // real-world test would inject *testing.T from TestSubset(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 TestSubset(t *testing.T)
    	require.Subset(t, []int{1, 2, 3}, []int{1, 2})
    	fmt.Println("passed")
    
    }


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