-
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.
Support getting dependencies info for a test
Closes #893
- Loading branch information
1 parent
39f8fa5
commit 563bd6d
Showing
10 changed files
with
221 additions
and
5 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
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
44 changes: 44 additions & 0 deletions
44
testng-core/src/test/java/test/dependent/issue893/DependencyTrackingListener.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,44 @@ | ||
package test.dependent.issue893; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestListener; | ||
import org.testng.ITestNGMethod; | ||
import org.testng.ITestResult; | ||
import org.testng.collections.Sets; | ||
|
||
public class DependencyTrackingListener implements ITestListener { | ||
private final Map<String, Set<String>> downstreamDependencies = new HashMap<>(); | ||
private final Map<String, Set<String>> upstreamDependencies = new HashMap<>(); | ||
|
||
@Override | ||
public void onTestStart(ITestResult result) { | ||
ITestContext context = result.getTestContext(); | ||
for (ITestNGMethod method : context.getAllTestMethods()) { | ||
String key = method.getQualifiedName(); | ||
downstreamDependencies | ||
.computeIfAbsent(key, k -> Sets.newHashSet()) | ||
.addAll( | ||
method.downstreamDependencies().stream() | ||
.map(ITestNGMethod::getQualifiedName) | ||
.collect(Collectors.toList())); | ||
upstreamDependencies | ||
.computeIfAbsent(key, k -> Sets.newHashSet()) | ||
.addAll( | ||
method.upstreamDependencies().stream() | ||
.map(ITestNGMethod::getQualifiedName) | ||
.collect(Collectors.toList())); | ||
} | ||
} | ||
|
||
public Map<String, Set<String>> getUpstreamDependencies() { | ||
return upstreamDependencies; | ||
} | ||
|
||
public Map<String, Set<String>> getDownstreamDependencies() { | ||
return downstreamDependencies; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
testng-core/src/test/java/test/dependent/issue893/MultiLevelDependenciesTestClassSample.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,17 @@ | ||
package test.dependent.issue893; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class MultiLevelDependenciesTestClassSample { | ||
@Test | ||
public void grandFather() {} | ||
|
||
@Test(dependsOnMethods = "grandFather") | ||
public void father() {} | ||
|
||
@Test(dependsOnMethods = "grandFather") | ||
public void mother() {} | ||
|
||
@Test(dependsOnMethods = {"father", "mother"}) | ||
public void child() {} | ||
} |
15 changes: 15 additions & 0 deletions
15
testng-core/src/test/java/test/dependent/issue893/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,15 @@ | ||
package test.dependent.issue893; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class TestClassSample { | ||
|
||
@Test | ||
public void independentTest() {} | ||
|
||
@Test(dependsOnMethods = "independentTest") | ||
public void dependentTest() {} | ||
|
||
@Test(dependsOnMethods = "independentTest") | ||
public void anotherDependentTest() {} | ||
} |