EclipseTestCollectorpublic class EclipseTestCollector extends Object Class for collecting all test cases in an eclipse plugin |
Constructors Summary |
---|
public EclipseTestCollector()Constructor
|
Methods Summary |
---|
public void | addTestCases(junit.framework.TestSuite suite, org.eclipse.core.runtime.Plugin plugin, java.lang.String expectedPackage)Searches through given plugin, adding all TestCase classes to given suite
if (plugin != null) {
Enumeration<?> entries = plugin.getBundle().findEntries("/", "*.class", true);
while (entries.hasMoreElements()) {
URL entry = (URL)entries.nextElement();
String filePath = entry.getPath().replace(".class", "");
try {
Class<?> testClass = getClass(filePath, expectedPackage);
if (isTestClass(testClass)) {
suite.addTestSuite(testClass);
}
}
catch (ClassNotFoundException e) {
// ignore, this is not the class we're looking for
//sLogger.log(Level.INFO, "Could not load class " + filePath);
}
}
}
| protected java.lang.Class | getClass(java.lang.String filePath, java.lang.String expectedPackage)Load the class given by the plugin aka bundle file path
String dotPath = filePath.replace('/", '.");
// remove the output folders, by finding where package name starts
int index = dotPath.indexOf(expectedPackage);
if (index == -1) {
throw new ClassNotFoundException();
}
String packagePath = dotPath.substring(index);
return Class.forName(packagePath);
| protected boolean | hasPublicConstructor(java.lang.Class testClass)Returns true if given class has a public constructor
try {
TestSuite.getTestConstructor(testClass);
} catch(NoSuchMethodException e) {
return false;
}
return true;
| protected boolean | isTestClass(java.lang.Class testClass)Returns true if given class should be added to suite
return TestCase.class.isAssignableFrom(testClass) &&
Modifier.isPublic(testClass.getModifiers()) &&
hasPublicConstructor(testClass);
|
|