-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline data provider listener invocation
Closes #3045
- Loading branch information
1 parent
4c7653d
commit 3b3d67c
Showing
6 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
testng-core/src/test/java/test/dataprovider/issue3045/DataProviderListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package test.dataprovider.issue3045; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.testng.IDataProviderListener; | ||
import org.testng.IDataProviderMethod; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestNGMethod; | ||
|
||
public class DataProviderListener implements IDataProviderListener { | ||
|
||
public static List<String> logs = new ArrayList<>(); | ||
|
||
@Override | ||
public void beforeDataProviderExecution( | ||
IDataProviderMethod dataProviderMethod, ITestNGMethod method, ITestContext iTestContext) { | ||
logs.add( | ||
testName(iTestContext) | ||
+ "-beforeDataProviderExecution-" | ||
+ dataProviderMethod.getMethod().getName()); | ||
} | ||
|
||
@Override | ||
public void afterDataProviderExecution( | ||
IDataProviderMethod dataProviderMethod, ITestNGMethod method, ITestContext iTestContext) { | ||
logs.add( | ||
testName(iTestContext) | ||
+ "-afterDataProviderExecution-" | ||
+ dataProviderMethod.getMethod().getName()); | ||
} | ||
|
||
private static String testName(ITestContext ctx) { | ||
return "[" + ctx.getName() + "]"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
testng-core/src/test/java/test/dataprovider/issue3045/DataProviderTestClassSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package test.dataprovider.issue3045; | ||
|
||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners({DataProviderListener.class}) | ||
public class DataProviderTestClassSample { | ||
|
||
@DataProvider | ||
public Object[][] dataProvider() { | ||
return new Object[][] {{"Test_1"}, {"Test_2"}, {"Test_3"}}; | ||
} | ||
|
||
@Test(dataProvider = "dataProvider") | ||
public void dataDrivenTest(String ignored) {} | ||
|
||
@Test | ||
public void normalTest() {} | ||
} |
18 changes: 18 additions & 0 deletions
18
...src/test/java/test/dataprovider/issue3045/DataProviderWithoutListenerTestClassSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package test.dataprovider.issue3045; | ||
|
||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class DataProviderWithoutListenerTestClassSample { | ||
|
||
@DataProvider | ||
public Object[][] dataProvider() { | ||
return new Object[][] {{"Test_1"}, {"Test_2"}, {"Test_3"}}; | ||
} | ||
|
||
@Test(dataProvider = "dataProvider") | ||
public void dataDrivenTest(String ignored) {} | ||
|
||
@Test | ||
public void normalTest() {} | ||
} |