The graph based dependency evaluation ist wrong, when one of the found classes does not contain any test methods. This can be the case if the package name is not only for testng tests, but can contain services etc. In this scenario the following method from the TestRunner:
private ListMultiMap<ITestNGMethod, ITestNGMethod> createClassDependencies(
ITestNGMethod[] methods, XmlTest test)
{
Map<String, List<ITestNGMethod>> classes = Maps.newHashMap();
// Note: use a List here to preserve the ordering but make sure
// we don't add the same class twice
List<XmlClass> sortedClasses = Lists.newArrayList();
for (XmlClass c : test.getXmlClasses()) {
classes.put(c.getName(), new ArrayList<ITestNGMethod>());
if (! sortedClasses.contains(c)) sortedClasses.add(c);
}
// Sort the classes based on their order of appearance in the XML
Collections.sort(sortedClasses, new Comparator<XmlClass>() {
@Override
public int compare(XmlClass arg0, XmlClass arg1) {
return arg0.getIndex() - arg1.getIndex();
}
});
Map<String, Integer> indexedClasses1 = Maps.newHashMap();
Map<Integer, String> indexedClasses2 = Maps.newHashMap();
int i = 0;
for (XmlClass c : sortedClasses) {
indexedClasses1.put(c.getName(), i);
indexedClasses2.put(i, c.getName());
i++;
}
ListMultiMap<String, ITestNGMethod> methodsFromClass = Maps.newListMultiMap();
for (ITestNGMethod m : methods) {
methodsFromClass.put(m.getTestClass().getName(), m);
}
ListMultiMap<ITestNGMethod, ITestNGMethod> result = Maps.newListMultiMap();
for (ITestNGMethod m : methods) {
String name = m.getTestClass().getName();
Integer index = indexedClasses1.get(name);
// The index could be null if the classes listed in the XML are different
// from the methods being run (e.g. the .xml only contains a factory that
// instantiates methods from a different class). In this case, we cannot
// perform any ordering.
if (index != null && index > 0) {
// Make this method depend on all the methods of the class in the previous
// index
String classDependedUpon = indexedClasses2.get(index - 1);
List<ITestNGMethod> methodsDependedUpon = methodsFromClass.get(classDependedUpon);
if (methodsDependedUpon != null) {
for (ITestNGMethod mdu : methodsDependedUpon) {
result.put(mdu, m);
}
}
}
}
return result;
}
creates no method dependencies when the successor class is not a test class with test methods. This results in a broken dependency tree for all following test methods. The intended behavior is that any method of a test class depends on all methods of the successor class!
Possible solutions are:
To not depend on "test.getXmlClasses()" to determine the sequence of possible classes (sortedClasses), but to use an indirect way with an iteration over all test methods and extract a list of test classes while iteration.
Extend the looping at the end to not only find a successor test class with -1, but iterate backwards so long until at least one successor test class with one active test method is found.
When using a testng.xml definition file, which contains a test definition with package based scanning of test classes. Like:
The graph based dependency evaluation ist wrong, when one of the found classes does not contain any test methods. This can be the case if the package name is not only for testng tests, but can contain services etc. In this scenario the following method from the TestRunner:
creates no method dependencies when the successor class is not a test class with test methods. This results in a broken dependency tree for all following test methods. The intended behavior is that any method of a test class depends on all methods of the successor class!
Possible solutions are:
If desired, i can provide a pull request.