Skip to content

Commit

Permalink
Streamline dataprovider invoking in abstract classes
Browse files Browse the repository at this point in the history
Closes #2800
  • Loading branch information
krmahadevan committed Oct 31, 2022
1 parent 8a34c03 commit bfdaf6d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2800: Running Test Classes with Inherited @Factory and @DataProvider Annotated Non-Static Methods Fail (Krishnan Mahadevan)
New: Ability to provide custom error message for assertThrows\expectThrows methods (Anatolii Yuzhakov)
Fixed: GITHUB-2780: Use SpotBugs instead of abandoned FindBugs
Fixed: GITHUB-2801: JUnitReportReporter is too slow
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -5,7 +5,7 @@ kotlin.code.style=official
# Note: testng.kotlin-library.gradle.kts adds kotlin-stdlib for testImplementation
kotlin.stdlib.default.dependency=false

testng.version=7.6.1
testng.version=7.6.2

group=org.testng

Expand Down
Expand Up @@ -610,7 +610,8 @@ private static IDataProviderMethod findDataProvider(

Class<?> cls = clazz.getRealClass();
boolean shouldBeStatic = false;
if (dataProviderClass != null) {
boolean isDataProviderClassAbstract = Modifier.isAbstract(cls.getModifiers());
if (dataProviderClass != null && !isDataProviderClassAbstract) {
cls = dataProviderClass;
shouldBeStatic = true;
}
Expand Down
Expand Up @@ -43,6 +43,12 @@

public class DataProviderTest extends SimpleBaseTest {

@Test(description = "GITHUB-2800")
public void testDataProviderFromAbstractClassWhenCoupledWithFactories() {
InvokedMethodNameListener listener = run(test.dataprovider.issue2800.TestClassGenerator.class);
assertThat(listener.getSucceedMethodNames()).containsExactly("hi", "hi");
}

@Test(description = "GITHUB-1691")
public void testDataProviderInfoIgnored() {
InvokedMethodNameListener listener =
Expand Down
@@ -0,0 +1,17 @@
package test.dataprovider.issue2800;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;

public abstract class AbstractTestClassGenerator {

@DataProvider(name = "dataProvider")
public Object[][] dataProvider() {
return new Object[][] {{"foo"}, {"bar"}};
}

@Factory(dataProvider = "dataProvider")
public Object[] testFactory(String value) {
return new Object[] {new TestClassSample()};
}
}
@@ -0,0 +1,3 @@
package test.dataprovider.issue2800;

public class TestClassGenerator extends AbstractTestClassGenerator {}
@@ -0,0 +1,9 @@
package test.dataprovider.issue2800;

import org.testng.annotations.Test;

public class TestClassSample {

@Test
public void hi() {}
}

0 comments on commit bfdaf6d

Please sign in to comment.