我有一个脚本可以检查返回的http状态代码。
import static org.hamcrest.Matchers.anyOf
import static org.hamcrest.Matchers.equalTo
import static org.hamcrest.MatcherAssert.assertThat
int[] expectedStatuses = [201,204]
def pollStatusCode = 202
def actualStatusCode = 201
如何断言actualStatusCode包含在expectedStatuses'的数组中。值?类似的东西:
assertThat(actualStatusCode, anyOf(equalTo(pollStatusCode), equalTo(expectedStatuses)))
有没有办法断言这种类型的值?
答案 0 :(得分:1)
assert actualStatusCode in expectedStatuses
或
assert expectedStatuses.contains(actualStatusCode)