How to assert any of the expected value in Go

Viewed 30

I am using assert.Contains() from testify and I have multiple expected values. Is there any way I can only use one assert.Contains() so that the test passes as long as the actual value matches at least one of the expected values? I am looking for something similar to the answer in this thread but not sure if there is anything like this in Go. Thanks for the help!


func TestExample(t *testing.T) {
    actual := "banana"
    expected := []string{"apple", "banana", "cherry"}
    assert.ContainsAny(t, actual, expected)
}
0 Answers
Related