use of org.eclipse.n4js.tester.domain.TestSuite in project n4js by eclipse.
the class TestTreeTransformerTest method createTestTree.
private TestTree createTestTree(final Multimap<String, String> suiteToCasesMapping) {
checkArgument(!suiteToCasesMapping.isEmpty());
final TestTree tree = new TestTree(new ID(randomUUID().toString()));
final List<TestSuite> suites = newArrayList();
suiteToCasesMapping.asMap().entrySet().forEach(entry -> {
final TestSuite suite = new TestSuite(entry.getKey());
entry.getValue().forEach(testCaseName -> suite.add(new TestCase(new ID(testCaseName), "class.name." + suite.getName(), "project.origin." + suite.getName(), testCaseName, "display.name." + testCaseName, URI.createURI("testURI_" + testCaseName))));
suites.add(suite);
});
tree.getSuites().addAll(suites);
return tree;
}
use of org.eclipse.n4js.tester.domain.TestSuite in project n4js by eclipse.
the class TesterDomainTest method testTreeContainsTest.
/**
*/
@Test
public void testTreeContainsTest() {
final TestTree tree = new TestTree(new ID(valueOf(randomUUID())));
final TestSuite a = new TestSuite("A");
a.addAll(newTestCase("1", "2", "3"));
final TestSuite b = new TestSuite("B");
b.addAll(newTestCase("4", "5", "6"));
final TestSuite a1 = new TestSuite("A.1");
a1.addAll(newTestCase("7", "8"));
final TestSuite a2 = new TestSuite("A.2");
a2.addAll(newTestCase("9", "10"));
final TestSuite a11 = new TestSuite("A.1.1");
a11.addAll(newTestCase("11", "12"));
a1.getChildren().add(a11);
a.getChildren().add(a1);
a.getChildren().add(a2);
tree.getSuites().add(a);
tree.getSuites().add(b);
assertNotNull(tree.getTestCase("1"));
assertNotNull(tree.getTestCase("2"));
assertNotNull(tree.getTestCase("3"));
assertNotNull(tree.getTestCase("4"));
assertNotNull(tree.getTestCase("5"));
assertNotNull(tree.getTestCase("6"));
assertNotNull(tree.getTestCase("7"));
assertNotNull(tree.getTestCase("8"));
assertNotNull(tree.getTestCase("9"));
assertNotNull(tree.getTestCase("10"));
assertNotNull(tree.getTestCase("11"));
assertNotNull(tree.getTestCase("12"));
assertNull(tree.getTestCase("13"));
assertNull(tree.getTestCase((String) null));
assertNull(tree.getTestCase((ID) null));
}
use of org.eclipse.n4js.tester.domain.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method collectSuitsForMethod.
private Collection<TestSuite> collectSuitsForMethod(final URI uri, final TModule module) {
final EObject object = module.eResource().getResourceSet().getEObject(uri, true);
if (object instanceof N4MethodDeclaration) {
final Type type = ((N4MethodDeclaration) object).getDefinedType();
if (type instanceof TMethod) {
final TMethod method = (TMethod) type;
final TestSuite testSuite = new TestSuite(getClassName(method));
testSuite.add(createTestCase(method, module));
return singletonList(testSuite);
}
}
return emptyList();
}
use of org.eclipse.n4js.tester.domain.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method collectTests.
private TestTree collectTests(final ResourceSet resSet, final IResourceDescriptions index, final URI... locations) {
// create test cases (aggregated in test suites)
final List<TestSuite> suites = newArrayList();
// create MultiMap from trimmed(!) URI -> original URIs for this prefix URI
final List<URI> testLocations = collectDistinctTestLocations(index, resSet, locations);
final HashMultimap<URI, URI> testLocationMapping = createTestLocationMapping(testLocations);
final Map<URI, TModule> moduleUri2Modules = loadModules(testLocationMapping.asMap().keySet(), index, resSet);
for (final URI moduleLocation : testLocationMapping.keys()) {
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
suites.addAll(collectSuitsForModule(module));
} else {
// we have URIs pointing to individual test methods -> collect all URIs
for (final URI uri : testLocationsForModule) {
suites.addAll(collectSuitsForMethod(uri, module));
}
}
}
// TODO what should be the name of the test tree is multiple test locations are available?
// Improve the way how we got the name of the test tree.
final ID sessionId = createTestSessionId();
String name = valueOf(sessionId);
if (locations.length > 0) {
final URI uri = locations[0];
name = valueOf(uri.trimFragment()).replaceFirst("platform:/resource/", "");
// name = name.replace("." + N4JS_FILE_EXTENSION, "");
if (name.lastIndexOf('.') > 0) {
name = name.substring(0, name.lastIndexOf('.'));
}
// Assuming one single test case.
if (uri.hasFragment() && !suites.isEmpty() && !suites.get(0).getTestCases().isEmpty()) {
name = name + "#" + suites.get(0).getTestCases().get(0).getDisplayName();
}
}
return new TestTree(sessionId, suites, name);
}
use of org.eclipse.n4js.tester.domain.TestSuite in project n4js by eclipse.
the class TestDiscoveryHelper method collectSuitsForModule.
private Collection<TestSuite> collectSuitsForModule(final TModule module) {
final List<TestSuite> suites = newArrayList();
// Collect all top level non-abstract exported classes, exclude everything else.
for (final TClass clazz : from(module.getTopLevelTypes()).filter(TClass.class).filter(c -> !c.isAbstract() && c.isExported())) {
final TestSuite testSuite = new TestSuite(getClassName(clazz));
for (final TMethod method : getAllTestMethodsOfClass(clazz)) {
final TestCase testCase = createTestCase(method, module, getClassName(clazz));
testSuite.add(testCase);
}
if (!isEmpty(testSuite)) {
suites.add(testSuite);
}
}
return suites;
}
Aggregations