简体   繁体   中英

How to use OR condition with TestNG assertions

Is there a way to do assertions with OR with TestNG?

This is what I am trying to find:

assertEquals(expected, value1 || value2); // Can be any number of values.

You could make a very simple wrapper around the TestNG code:

private void assertContains(Object actual, Object ... expected) {
    assertTrue(Arrays.asList(expected).contains(actual));
}

I briefly looked through the TestNG source code and didn't see any methods similar to the method above, but I am not very familiar with the TestNG patterns.

如果是字符串比较,您可以使用:

        assertTrue(myText.equals("my text") || myText.equals("your text") || myText.equals("his text"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM