0

I have a Test Automation project using TestNg.

I want to make sure certain configurations are enabled before I start some of the tests. I have written this as a test and marked other tests as dependent on this. So I have used the TestNG param "dependsOnMethods" for all the individual tests which are dependent on this check.

These tests are distributed across multiple classes and I currently have to do this check in each and every class, which works fine if all tests are passing, but if there is a configuration missing, I get a bunch of errors because the test which is doing this check fails and then I have a copy of this failure in almost every class I have.

So instead of 1 failure, I end up with 10 failures, as this failure happens multiple times.

This can't be a @BeforeTest or @BeforeMethod or @BeforeClass since this is required for only a few of the tests in a TestClass.

I can set a Global Flag based on the failure of this test, but then again I can't skip Testng tests based on Flags. So I will get false Negatives.

Is there a way to create a test in a parent class and skip some tests if this fails?

1

3 Answers 3

0

I'm not really sure if TestNG allows to have a common dependsOnMethods for multiple classes.

You can try another option called dependsOnGroups.

Here is an article to help you with it. As I am not aware of the copyrights of the content of the reference article. I am only giving a link rather than copying the content here.

You can also try out solutions given here.

0

So if one has to skip tests based on a boolean you can use SkipException. This helps when we don't want to depend on a method call using dependsOnMethods param of TestNg

@Test()
public void testDependingOnData {
  if(dataMissing) {
     throw new SkipException("We skip this Test");
  }
  // Test Steps here
}

This article helped me with the solution - https://www.seleniumeasy.com/testng-tutorials/skip-test-in-testng

-1

By using grouping. You can create a group of tasks you want to execute and then make a suite for it and only those test cases will run. 2. By using enable and disable in the test method such that only the test case where enabled = true will execute and the test methods with enabled = false will not.

1
  • Alwin, thank you for taking the time to answer this question. I would like to point out that links unrelated to the question / answer are not permitted. Links related to the question are permitted, as long as the question is not link-only and provided if there is any promotion for which you benefit it is both relevant and disclosed as such in the post. Thank you!
    – corsiKa
    Commented Feb 26, 2021 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.