Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline dataprovider invoking in abstract classes #2814

Merged
merged 1 commit into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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() {}
}