-
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 native injection w.r.t cloning
Closes #1994 Currently as part of supporting native injection TestNG resorts to invoking the “clone()” method on the parameter being natively injected. This becomes a problem because XmlTest is the only internal TestNG object that implements the Cloneable interface wherein it resorts to something like a deep copy and adds the cloned instance to the XmlSuite. This causes a lot of phony XmlTest objects to be added up to the suite and causes issues as detailed in the bug. Fixed this by introducing a marker interface to indicate to TestNG to skip cloning and use the object as is. Annotated “XmlTest” with this annotation so that we dont clone xmltest but instead use it as is. Yes this will expose the XmlTest object, but its already exposed to the end user via various different means. So I guess we are ok here.
- Loading branch information
1 parent
f1111e0
commit 96ea07b
Showing
6 changed files
with
101 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.testng.annotations; | ||
|
||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marker interface which when used on a type will ensure that TestNG does not clone the object but | ||
* instead uses it as is when TestNG resorts to dependency injection. | ||
*/ | ||
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface SkipCloning { | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
src/test/java/test/parameters/issue1994/TestclassSample.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,32 @@ | ||
package test.parameters.issue1994; | ||
|
||
import org.testng.ISuite; | ||
import org.testng.ISuiteListener; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
import org.testng.xml.XmlTest; | ||
|
||
@Listeners(TestclassSample.class) | ||
public class TestclassSample implements ISuiteListener { | ||
|
||
public static int count = 0; | ||
|
||
@BeforeClass | ||
public void beforeClass(XmlTest xmlTest) { | ||
} | ||
|
||
@Test | ||
public void testMethod() { | ||
} | ||
|
||
@Override | ||
public void onFinish(ISuite suite) { | ||
setCount(suite.getXmlSuite().getTests().size()); | ||
} | ||
|
||
private static void setCount(int count) { | ||
TestclassSample.count = count; | ||
} | ||
|
||
} |