use of org.eclipse.n4js.tooling.tester.model.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method addOrCreateSuite.
private TestSuite addOrCreateSuite(N4JSWorkspaceConfigSnapshot ws, TClass clazz, Map<String, TestSuite> suites) {
String suiteKey = getTestCatalogNameFor(ws, clazz);
TestSuite suite = suites.get(suiteKey);
if (suite == null) {
suite = new TestSuite(suiteKey);
suites.put(suiteKey, suite);
}
return suite;
}
use of org.eclipse.n4js.tooling.tester.model.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method collectTests.
/**
* Collects all test methods available at the given location and returns a {@link TestTree} in which each test
* method is represented by a {@link TestCase}. The location may point to an N4JS project or a folder or file within
* an N4JS project.
*
* @param resourceSetAccess
* the accessor for the resource set
*
* @param locations
* the locations referencing to a resource. Can be an N4JS project, or a folder or a file within an N4JS
* project.
* @return The test tree representing one or more test cases. Never returns with {@code null}, but the returned test
* tree may be empty.
*/
private TestTree collectTests(N4JSWorkspaceConfigSnapshot ws, Function<? super URI, ? extends ResourceSet> resourceSetAccess, final List<URI> locations) {
// create test cases (aggregated in test suites)
final Map<String, TestSuite> suites = new LinkedHashMap<>();
// create MultiMap from trimmed(!) URI -> original URIs for this prefix URI
final List<URI> testLocations = collectDistinctTestLocations(ws, resourceSetAccess, locations);
// module URI --> test case URIs
final HashMultimap<URI, URI> testLocationMapping = createTestLocationMapping(testLocations);
// module URI --> module
final Map<URI, TModule> moduleUri2Modules = loadModules(testLocationMapping.asMap().keySet(), resourceSetAccess);
for (final URI moduleLocation : testLocationMapping.keySet()) {
final TModule module = moduleUri2Modules.get(moduleLocation);
if (null == module) {
// Assuming broken AST.
continue;
}
// make sure trimmed URIs processed before non-trimmed ones, in other words we collects all tests for
// test modules first, then later we can skip individual test collecting for test methods.
// so we can make sure, iff there are more than one elements in the list, and the first one equals to
// the module location URI (with any fragments), we can skip the processing, since the whole module
// contains the individual test locations
final List<URI> testLocationsForModule = newArrayList(testLocationMapping.get(moduleLocation));
testLocationsForModule.sort(URI_COMPARATOR);
if (testLocationsForModule.get(0).equals(moduleLocation)) {
// The first item is referencing the entire module
// --> collect all test methods in module and ignore remaining URIs
collectTestCasesAndSuitesForModule(ws, module, suites);
} else {
// we have URIs pointing to individual test methods -> collect all URIs
for (final URI uri : testLocationsForModule) {
collectTestSuiteAndTestCaseForMethod(ws, uri, module, suites);
}
}
}
// if test cases are selected, name of tree is first test method and number of more tests
final ID sessionId = createTestSessionId();
String name = valueOf(sessionId);
if (!locations.isEmpty()) {
final URI uri = locations.get(0);
name = valueOf(uri.trimFragment()).replaceFirst("platform:/resource/", "");
if (name.lastIndexOf('.') > 0) {
name = name.substring(0, name.lastIndexOf('.'));
}
// Assuming one single test case.
if (uri.hasFragment() && !suites.isEmpty() && !suites.values().iterator().next().getTestCases().isEmpty()) {
name += "#" + suites.values().iterator().next().getTestCases().get(0).getDisplayName();
}
if (locations.size() > 1) {
name += " and " + (locations.size() - 1) + " more";
}
}
return new TestTree(sessionId, suites.values(), name).sort();
}
use of org.eclipse.n4js.tooling.tester.model.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method collectTestCasesAndSuitesForModule.
/**
* Collect test cases for all all top level non-abstract exported classes, exclude everything else.
*/
private void collectTestCasesAndSuitesForModule(N4JSWorkspaceConfigSnapshot ws, TModule module, Map<String, TestSuite> suites) {
for (final TClass clazz : from(module.getTypes()).filter(TClass.class).filter(c -> !c.isAbstract() && c.isExported())) {
Iterable<TMethod> testMethods = getAllTestMethodsOfClass(clazz);
if (testMethods.iterator().hasNext()) {
TestSuite testSuite = addOrCreateSuite(ws, clazz, suites);
for (final TMethod method : testMethods) {
final TestCase testCase = createTestCase(method, module, getTestCatalogNameFor(ws, clazz));
testSuite.add(testCase);
}
}
}
}
use of org.eclipse.n4js.tooling.tester.model.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method collectTestSuiteAndTestCaseForMethod.
private void collectTestSuiteAndTestCaseForMethod(N4JSWorkspaceConfigSnapshot ws, URI uri, TModule module, Map<String, TestSuite> suites) {
final EObject object = module.eResource().getResourceSet().getEObject(uri, true);
final Type type = (object instanceof N4MethodDeclaration) ? ((N4MethodDeclaration) object).getDefinedType() : (object instanceof TMethod) ? (TMethod) object : null;
if (type instanceof TMethod) {
final TMethod method = (TMethod) type;
TestSuite testSuite = addOrCreateSuite(ws, (TClass) method.getContainingType(), suites);
testSuite.add(createTestCase(ws, method, module));
}
}
Aggregations