Search in sources :

Example 6 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree 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 7 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class TestCatalogSupplier method get.

/**
 * Returns with the test catalog as a string representing all available tests in the workspace. This method may
 * return with a test catalog of an empty {@link TestTree test tree} if the the {@link Platform platform} is not
 * running.
 *
 * @return the test catalog as a JSON formatted string.
 */
@Override
public String get() {
    try {
        final TestTree testTree = getTreeForAllTests();
        final Object testCatalogObject = treeTransformer.apply(testTree);
        return objectMapper.writeValueAsString(testCatalogObject);
    } catch (final Exception e) {
        throw new RuntimeException("Error while assembling test catalog.", e);
    }
}
Also used : TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 8 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree 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 9 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class TesterFrontEnd method computeDerivedValues.

/**
 * Similar to {@link RunnerFrontEnd#computeDerivedValues(RunConfiguration)}, but for testing.
 */
public void computeDerivedValues(TestConfiguration config) {
    // A) compute derived values for the run(!) configuration (will delegate to runner)
    runnerFrontEnd.computeDerivedValues(config, false);
    // B) compute derived values for the test configuration
    // B.1) compute the test tree (note: will create a new session ID every time this is called)
    final TestTree testTree = testDiscoveryHelper.collectTests(config.getUserSelection());
    config.setTestTree(testTree);
    // B.2) pass test tree as execution data
    try {
        // Read out port of running IDE-server and pass it to end-point-computation in tree-transformer
        TesterActivator testerActivator = TesterActivator.getInstance();
        int port = testerActivator != null ? testerActivator.getServerPort() : PORT_PLACEHOLDER_MAGIC_NUMBER;
        config.setResultReportingPort(port);
        testTreeTransformer.setHttpServerPort(Integer.toString(port));
        final String testTreeAsJSON = objectMapper.writeValueAsString(testTreeTransformer.apply(testTree));
        config.setExecutionData(TestConfiguration.EXEC_DATA_KEY__TEST_TREE, testTreeAsJSON);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // B.3) delegate further computation to the specific tester implementation
    ITester tester = testerRegistry.getTester(config);
    tester.prepareConfiguration(config);
}
Also used : IOException(java.io.IOException) TesterActivator(org.eclipse.n4js.tester.internal.TesterActivator) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 10 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class TesterFrontEnd method test.

/**
 * Similar to {@link RunnerFrontEnd#run(RunConfiguration, IExecutor)}, but for testing.
 */
public Process test(TestConfiguration config, IExecutor executor) {
    final TestTree testTree = config.getTestTree();
    // prepare HTTP server for receiving test results
    int port = testerFacade.prepareTestSession(testTree);
    updateTestTreeDescription(config, port);
    // actually launch the test
    ITester tester = testerRegistry.getTester(config);
    return tester.test(config, executor, runnerFrontEnd);
}
Also used : TestTree(org.eclipse.n4js.tester.domain.TestTree)

Aggregations

TestTree (org.eclipse.n4js.tester.domain.TestTree)25 Test (org.junit.Test)14 UUID.randomUUID (java.util.UUID.randomUUID)7 ID (org.eclipse.n4js.tester.domain.ID)7 TestSuite (org.eclipse.n4js.tester.domain.TestSuite)7 TestCase (org.eclipse.n4js.tester.domain.TestCase)4 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 URI (org.eclipse.emf.common.util.URI)1 ExitCodeException (org.eclipse.n4js.hlc.base.ExitCodeException)1 TestConfiguration (org.eclipse.n4js.tester.TestConfiguration)1 ITesterDescriptor (org.eclipse.n4js.tester.extension.ITesterDescriptor)1 TesterActivator (org.eclipse.n4js.tester.internal.TesterActivator)1 TModule (org.eclipse.n4js.ts.types.TModule)1