-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
Closes #3111 TestNG now exposes the IParameterInfo interface Via which you can extract the following details Pertaining to a factory powered test. * the index - which would match with what was Specified in the “indices” attribute of the “Factory” Annotation. If nothing was specified, then this Would be equal to a running count on the total instances. * current index - which represents a running count On the total instances. * The parameters of the factory method * The instance that was produced.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.testng; | ||
|
||
/** Represents the ability to retrieve the parameters associated with a factory method. */ | ||
public interface IParameterInfo { | ||
|
||
/** @return - The actual instance associated with a factory method */ | ||
Object getInstance(); | ||
|
||
/** | ||
* @return - The actual index of instance associated with a factory method. This index has a 1:1 | ||
* correspondence with what were specified via the <code>indices</code> attribute of the | ||
* <code>@Factory</code> annotation.</code></code>. For e.g., lets say you specified the | ||
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 11, corretto, ubuntu, America/New_York, ru_RU
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 11, corretto, ubuntu, America/New_York, ru_RU
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 11, liberica, macos, Pacific/Chatham, de_DE
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 11, liberica, macos, Pacific/Chatham, de_DE
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 17, corretto, macos, Pacific/Chatham, fr_FR, stress JIT
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 17, corretto, macos, Pacific/Chatham, fr_FR, stress JIT
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 21, oracle, ubuntu, America/New_York, de_DE
Check failure on line 12 in testng-core-api/src/main/java/org/testng/IParameterInfo.java GitHub Actions / 21, oracle, ubuntu, America/New_York, de_DE
|
||
* indices to the "1" and your factory returned 4 instances, then the instance on which this | ||
* method is invoked would have the value as "1". | ||
*/ | ||
int getIndex(); | ||
|
||
/** | ||
* @return - returns an index which indicates the running position in the array of test class | ||
* instances that were produced by a <code>@Factory</code> annotated constructor or static | ||
* method. For e.g., lets say your <code>@Factory</code> method returned 4 instances, then | ||
* each of the invocations to this method would return a value from <code>0</code> to <code>3 | ||
* </code> | ||
*/ | ||
int currentIndex(); | ||
|
||
/** @return - The parameters associated with the factory method as an array. */ | ||
Object[] getParameters(); | ||
|
||
static Object embeddedInstance(Object original) { | ||
if (original instanceof IParameterInfo) { | ||
return ((IParameterInfo) original).getInstance(); | ||
} | ||
return original; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
package org.testng.internal; | ||
|
||
/** Represents the ability to retrieve the parameters associated with a factory method. */ | ||
public interface IParameterInfo { | ||
|
||
/** @return - The actual instance associated with a factory method */ | ||
Object getInstance(); | ||
|
||
/** @return - The actual index of instance associated with a factory method */ | ||
int getIndex(); | ||
|
||
/** @return - The parameters associated with the factory method as an array. */ | ||
Object[] getParameters(); | ||
|
||
static Object embeddedInstance(Object original) { | ||
if (original instanceof IParameterInfo) { | ||
return ((IParameterInfo) original).getInstance(); | ||
} | ||
return original; | ||
} | ||
} | ||
/** | ||
* Represents the ability to retrieve the parameters associated with a factory method. | ||
* | ||
* @deprecated - This interface stands deprecated as of TestNG <code>7.11.0</code>. | ||
*/ | ||
@Deprecated | ||
public interface IParameterInfo extends org.testng.IParameterInfo {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package test.factory.issue3111; | ||
|
||
import org.testng.Reporter; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class SimpleFactoryPoweredTestSample { | ||
|
||
private final int i; | ||
|
||
@Factory(dataProvider = "data") | ||
public SimpleFactoryPoweredTestSample(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Reporter.log(Integer.toString(i)); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] data() { | ||
return new Object[][] {{1}, {2}, {3}}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package test.factory.issue3111; | ||
|
||
import org.testng.Reporter; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class SimpleFactoryPoweredTestWithIndicesSample { | ||
|
||
private final int i; | ||
|
||
@Factory( | ||
dataProvider = "data", | ||
indices = {1}) | ||
public SimpleFactoryPoweredTestWithIndicesSample(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Reporter.log(Integer.toString(i)); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] data() { | ||
return new Object[][] {{1}, {2}, {3}}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package test.factory.issue3111; | ||
|
||
import org.testng.Reporter; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class SimpleFactoryPoweredTestWithoutDataProviderSample { | ||
|
||
private final int i; | ||
|
||
public SimpleFactoryPoweredTestWithoutDataProviderSample(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Reporter.log(Integer.toString(i)); | ||
} | ||
|
||
@Factory | ||
public static Object[] data() { | ||
return new Object[] { | ||
new SimpleFactoryPoweredTestWithoutDataProviderSample(1), | ||
new SimpleFactoryPoweredTestWithoutDataProviderSample(2), | ||
new SimpleFactoryPoweredTestWithoutDataProviderSample(3), | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package test.factory.issue3111; | ||
|
||
import org.testng.Reporter; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample { | ||
|
||
private final int i; | ||
|
||
public SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Reporter.log(Integer.toString(i)); | ||
} | ||
|
||
@Factory(indices = {1}) | ||
public static Object[] data() { | ||
return new Object[] { | ||
new SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample(1), | ||
new SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample(2), | ||
new SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample(3), | ||
}; | ||
} | ||
} |