Search in sources :

Example 1 with TestSuite

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;
}
Also used : TestSuite(org.eclipse.n4js.tester.domain.TestSuite) TestCase(org.eclipse.n4js.tester.domain.TestCase) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 2 with TestSuite

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));
}
Also used : TestSuite(org.eclipse.n4js.tester.domain.TestSuite) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TestTree(org.eclipse.n4js.tester.domain.TestTree) Test(org.junit.Test)

Example 3 with TestSuite

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();
}
Also used : Type(org.eclipse.n4js.ts.types.Type) EcoreUtil2.getContainerOfType(org.eclipse.xtext.EcoreUtil2.getContainerOfType) FileExtensionType(org.eclipse.n4js.fileextensions.FileExtensionType) TMethod(org.eclipse.n4js.ts.types.TMethod) TestSuite(org.eclipse.n4js.tester.domain.TestSuite) EObject(org.eclipse.emf.ecore.EObject) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration)

Example 4 with TestSuite

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);
}
Also used : TestSuite(org.eclipse.n4js.tester.domain.TestSuite) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 5 with TestSuite

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;
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) TestSuite(org.eclipse.n4js.tester.domain.TestSuite) TestCase(org.eclipse.n4js.tester.domain.TestCase) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

TestSuite (org.eclipse.n4js.tester.domain.TestSuite)10 UUID.randomUUID (java.util.UUID.randomUUID)7 ID (org.eclipse.n4js.tester.domain.ID)7 TestTree (org.eclipse.n4js.tester.domain.TestTree)7 TestCase (org.eclipse.n4js.tester.domain.TestCase)5 Test (org.junit.Test)3 TMethod (org.eclipse.n4js.ts.types.TMethod)2 Function (com.google.common.base.Function)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 FileExtensionType (org.eclipse.n4js.fileextensions.FileExtensionType)1 N4MethodDeclaration (org.eclipse.n4js.n4JS.N4MethodDeclaration)1 TClass (org.eclipse.n4js.ts.types.TClass)1 TModule (org.eclipse.n4js.ts.types.TModule)1 Type (org.eclipse.n4js.ts.types.Type)1 EcoreUtil2.getContainerOfType (org.eclipse.xtext.EcoreUtil2.getContainerOfType)1