Questions tagged [testng-annotation-test]

Test Annotations: The @Test annotation marks a class or a method as part of the test.

@Test Annotation: The @Test annotation marks a class or a method as part of the test.

Documentation: TestNG

75 questions
3
votes
2 answers

Common annotations used in different test classes

I have a question regarding annotations like @BeforeTest or @BeforeMethod. Is it possible to set a global annotations, so that all my test classes will be use them? I have in my framework over 20 test classes with a lot of test methods. Every test…
Kamil
  • 77
  • 6
3
votes
3 answers

TestNG - How to avoid checkstyle error when number of parameters exceeds 7?

When number of arguments to a method exceeds 7, checkstyle error (i.e., More than 7 parameters (found 8). [ParameterNumber]) would be thrown. Hence, for below method also it is throwing. Generally, checkstyle error can be avoided by using String…
2
votes
1 answer

How can I dynamically assign test groups to test methods and @BeforeXXX and @AfterXXX annotated methods during runtime?

My Requirement: I have around 100 tests in my test suite. I don't want to hardcode the group name in the tests source code. I want to choose the tests that I want to run each time but want to pass that list from an external source (csv/json/xml,…
2
votes
2 answers

Only the last @Test is being executed when using IMethodInterceptor as Listener in TestNG

I'm trying to use @Factory to create multiple instances of a class and print the values in the same order that we have passed by using IMethodInterceptor listener: public class MainFactoryClass implements IMethodInterceptor { @Factory public…
2
votes
1 answer

Why TestNG Optional parameter coming with double quotes

With TestNG 7.0.0 and Eclipse 2019-03 When trying to use @Optional Parameters value, it comes with double-quotes. Not getting why? Check the below screenshot for details. [] What am I missing? I expect the optional value without quotes just like…
1
vote
1 answer

If we can use dataProvider using by extending class then why we are using dataProviderClass parameter in @Test annotation ? correct me if I wrong

// This is from another file but same package. public class EmpData { @DataProvider public Object[][] getData() { Object[][] data= {{"Hello","text","1"},{"bye","Message","32"},{"solo","call","678"}}; return data; …
1
vote
0 answers

Is there a way to add group names before executing a test in TestNG (Java)?

For each test (@Test) we have to add group names dynamically before executing them. Before executing @Test method, data provider is invoked and it will give the list of group names to that particular test case falls in. Is there any way to add group…
1
vote
0 answers

Why parallel="instances" running tests within same class instance in different threads

Why following code is running tests in different threads? Test class: public class InstancesOfClass { public static int counter=0; public InstancesOfClass() { counter++; } @Test public void testA() { …
a Learner
  • 4,944
  • 10
  • 53
  • 89
1
vote
2 answers

How to run the specified testng case by code?

How to run the specified testNG case by code? The following code: public class TestNGTest { @Test public void test() { System.out.println("test ########"); } @Test public void test2() { …
joy
  • 29
  • 4
1
vote
2 answers

TestNG assign programatically DataProvider

If I have a method: @Test(dataProvider = "webTarget") void testFirst(WebTarget target) { // ... } Can I create a Listener or something in TestNG, that if I have a method: @Test void testFirst(WebTarget target) { // ... } then it…
1
vote
1 answer

TestNg grouping

We are using testNg as our test framework, where in we use @groups annotation for running specific tests. How can we customize this annotation to make the groups specified in the build target are considered in 'AND' instead of…
Mahima
  • 178
  • 8
1
vote
2 answers

@DataProvider with return type as Iterator

I try to execute the simple test case which call dataProvider and this dataProvider has return type as Iterator, I know this return type is not accept by @DataProvider method but after excute the below programm i get the blank output…
1
vote
1 answer

can we pass the expected Exception in testNG DataProvider

I am writing integration tests for my code, and the tests are data driven, different data will give back different result or throw exceptions. @Test(dataProvider = "successTestData") public void (String testData1, String testData2) { //do…
1
vote
0 answers
1
vote
1 answer

How to access dependsOnMethod or dependsOnGroup across different classes having TestNG tests?

We're writing a TestNG based regression suite. Soon, we'll have tests across different classes, wherein the Test in Class A should run only after tests in Class B has run, also we'll need a facility to access some methods, variables which will be…
user2451016
  • 1,857
  • 3
  • 20
  • 44
1
2 3 4 5