Test (Class<?> root) { Set<Class<?>> classes = new LinkedHashSet<>(collectDeclaredClasses(root, true)); Map<Class<?>, TestSuite> classSuites = new HashMap<>(); for (Class<?> aClass : classes) { classSuites.put(aClass, hasTestMethods(aClass) ? new TestSuite(aClass) : new TestSuite(aClass.getCanonicalName())); } for (Class<?> aClass : classes) { if (aClass.getEnclosingClass() != null && classes.contains(aClass.getEnclosingClass())) { classSuites.get(aClass.getEnclosingClass()).addTest(classSuites.get(aClass)); } } return classSuites.get(root); }