Can we use conditions with expectedExceptions in TestNG

I'm using TestNG. I'm having a test case which is running for both admin users as well as standard users. For admin users expected behavior is no exceptions and task get success while for standard users expected is a exception. In this kind of scenario what is the best approach?

  1. Should we write 2 separate test for user ?
  2. Is there a way to use expectedExceptions annotation with some condition

I can use try catch inside the method and check for the condition. But I think it is not a good practice.

Upvotes: 1

Views: 129

Answers (1)

Mureinik
Mureinik

Reputation: 311998

The expectedExceptions doesn't have any additional properties (like conditions).

Just write two separate tests, one for admins and one for regular users.

Upvotes: 2

Related Questions