forked from testng-team/testng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to access factory method params info
Closes testng-team#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
1 parent
249ea08
commit b64403e
Showing
14 changed files
with
226 additions
and
35 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
36 changes: 36 additions & 0 deletions
36
testng-core-api/src/main/java/org/testng/IParameterInfo.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,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. For e.g., lets say you specified the 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; | ||
} | ||
} |
26 changes: 7 additions & 19 deletions
26
testng-core-api/src/main/java/org/testng/internal/IParameterInfo.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 |
---|---|---|
@@ -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 {} |
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
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
26 changes: 26 additions & 0 deletions
26
testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestSample.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,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}}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithIndicesSample.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,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}}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...c/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderSample.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,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), | ||
}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample.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,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), | ||
}; | ||
} | ||
} |
Oops, something went wrong.