Jagriti,
You can do this very easily by following the below steps:
The below sample shows this in action.
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SelectiveConfigurationExecutionSample {
@BeforeMethod
public void beforeMethod(ITestResult result) {
ITestNGMethod method = result.getMethod();
SkipSetup skipSetup =
method.getConstructorOrMethod().getMethod().getAnnotation(SkipSetup.class);
if (skipSetup == null) {
System.err.println("Running setup for the method " + method.getMethodName() + "()");
} else {
System.err.println("Skipping setup for the method " + method.getMethodName() + "()");
}
}
@Test
public void a() {}
@Test
public void b() {}
@Test
@SkipSetup
public void c() {}
@Test
public void d() {}
@Test
public void e() {}
@Test
@SkipSetup
public void f() {}
@Test
public void g() {}
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({METHOD})
@interface SkipSetup {}
}
Running setup for the method a()
Running setup for the method b()
Skipping setup for the method c()
Running setup for the method d()
Running setup for the method e()
Skipping setup for the method f()
Running setup for the method g()
===============================================
Default Suite
Total tests run: 7, Passes: 7, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.com/
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Did you create a new class with the custom annotation SkipSetup ?
In the sample that I shared, I included its definition as a nested class. But you can have it reside in a separate file as well.
SkipSetup is a marker annotation.
To learn more about annotations in general refer https://dzone.com/articles/creating-custom-annotations-in-java
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.com/
From: <testng...@googlegroups.com> on behalf of Jagriti Jain <jagri...@gmail.com>
Reply-To: <testng...@googlegroups.com>
Date: Thursday, April 25, 2019 at 2:41 PM
To: testng-users <testng...@googlegroups.com>
--