Я пытаюсь написать код, который рекурсивно добавляет TestSuites в проект к набору наборов, расположенных в корне иерархии пакетов.
Я уже написал код, который возвращает объект Collection, содержащий объект File для каждого набора тестов, найденного в моем проекте.
Теперь я пытаюсь просмотреть их и добавить в TestSuite в файл с именем AllTests.java:
public static Test suite() throws IOException, ClassNotFoundException {
TestSuite suite = new TestSuite();
//Code not included for getTestSuites() in this snippet.
Collection<File> testSuites = getTestSuites();
for(File f: testSuites) {
//Truncate the path of the test to the beginning of the package name
String testName = f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf("net"));
//Replace backslashes with fullstops
testName = testName.replaceAll("\\\\", ".");
//Take the .class reference off the end of the path to the class
testName = testName.replaceAll(".class", "");
//Add TestSuite to Suite of Suites
Class<? extends Test> test = (Class<? extends Test>) AllTests.class.getClassLoader().loadClass(testName);
suite.addTest(test);
}
К сожалению, я получаю следующую ошибку компилятора в строке suite.addTest(test):
Метод addTest(Test) в типе TestSuite неприменим для аргументов (Класс ‹ Capture#3-of ? extends Test>)
Совершаю ли я фундаментальную ошибку, предполагая, что ссылка Class‹ Test> и ссылка Test — это одно и то же?