Search in sources :

Example 6 with TestStartEvent

use of org.gradle.api.internal.tasks.testing.TestStartEvent in project gradle by gradle.

the class TestClassExecutionEventGenerator method testClassFinished.

@Override
public void testClassFinished(Throwable failure) {
    long now = clock.getCurrentTime();
    try {
        if (failure != null) {
            if (currentTests.isEmpty()) {
                String testName = testsStarted ? "executionError" : "initializationError";
                DefaultTestDescriptor initializationError = new DefaultTestDescriptor(idGenerator.generateId(), currentTestClass.getClassName(), testName);
                resultProcessor.started(initializationError, new TestStartEvent(now));
                resultProcessor.failure(initializationError.getId(), failure);
                resultProcessor.completed(initializationError.getId(), new TestCompleteEvent(now));
            } else {
                for (Object test : currentTests) {
                    resultProcessor.failure(test, failure);
                    resultProcessor.completed(test, new TestCompleteEvent(now));
                }
            }
        }
        resultProcessor.completed(currentTestClass.getId(), new TestCompleteEvent(now));
    } finally {
        testsStarted = false;
        currentTests.clear();
        currentTestClass = null;
    }
}
Also used : DefaultTestDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestDescriptor) TestStartEvent(org.gradle.api.internal.tasks.testing.TestStartEvent) TestCompleteEvent(org.gradle.api.internal.tasks.testing.TestCompleteEvent)

Example 7 with TestStartEvent

use of org.gradle.api.internal.tasks.testing.TestStartEvent in project gradle by gradle.

the class TestNGTestResultProcessorAdapter method onTestFinished.

private void onTestFinished(ITestResult iTestResult, TestResult.ResultType resultType) {
    Object testId;
    TestStartEvent startEvent = null;
    synchronized (lock) {
        testId = testMethodId.remove(iTestResult);
        if (testId == null) {
            // This can happen when a method fails which this method depends on
            testId = idGenerator.generateId();
            Object parentId = testMethodParentId.get(iTestResult.getMethod());
            startEvent = new TestStartEvent(iTestResult.getStartMillis(), parentId);
        }
    }
    if (startEvent != null) {
        // Synthesize a start event
        resultProcessor.started(new DefaultTestMethodDescriptor(testId, iTestResult.getTestClass().getName(), iTestResult.getName()), startEvent);
    }
    if (resultType == TestResult.ResultType.FAILURE) {
        resultProcessor.failure(testId, iTestResult.getThrowable());
    }
    resultProcessor.completed(testId, new TestCompleteEvent(iTestResult.getEndMillis(), resultType));
}
Also used : DefaultTestMethodDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestMethodDescriptor) TestStartEvent(org.gradle.api.internal.tasks.testing.TestStartEvent) TestCompleteEvent(org.gradle.api.internal.tasks.testing.TestCompleteEvent)

Example 8 with TestStartEvent

use of org.gradle.api.internal.tasks.testing.TestStartEvent in project gradle by gradle.

the class TestNGTestResultProcessorAdapter method onStart.

@Override
public void onStart(ITestContext iTestContext) {
    TestDescriptorInternal testInternal;
    Object parentId;
    synchronized (lock) {
        Object id = idGenerator.generateId();
        testInternal = new DefaultTestSuiteDescriptor(id, iTestContext.getName());
        parentId = suiteId.get(iTestContext.getSuite());
        xmlTestIds.put(iTestContext.getCurrentXmlTest(), id);
        testId.put(iTestContext, testInternal.getId());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodParentId.put(method, testInternal.getId());
        }
    }
    resultProcessor.started(testInternal, new TestStartEvent(iTestContext.getStartDate().getTime(), parentId));
}
Also used : TestDescriptorInternal(org.gradle.api.internal.tasks.testing.TestDescriptorInternal) ITestNGMethod(org.testng.ITestNGMethod) TestStartEvent(org.gradle.api.internal.tasks.testing.TestStartEvent) DefaultTestSuiteDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestSuiteDescriptor)

Example 9 with TestStartEvent

use of org.gradle.api.internal.tasks.testing.TestStartEvent in project gradle by gradle.

the class TestNGTestResultProcessorAdapter method onTestStart.

@Override
public void onTestStart(ITestResult iTestResult) {
    TestDescriptorInternal testInternal;
    Object parentId;
    synchronized (lock) {
        String name = calculateTestCaseName(iTestResult);
        testInternal = new DefaultTestMethodDescriptor(idGenerator.generateId(), iTestResult.getTestClass().getName(), name);
        Object oldTestId = testMethodId.put(iTestResult, testInternal.getId());
        assert oldTestId == null : "Apparently some other test has started but it hasn't finished. " + "Expect the resultProcessor to break. " + "Don't expect to see this assertion stack trace due to the current architecture";
        parentId = testMethodParentId.get(iTestResult.getMethod());
        assert parentId != null;
    }
    resultProcessor.started(testInternal, new TestStartEvent(iTestResult.getStartMillis(), parentId));
    if (iTestResult.getThrowable() instanceof UnrepresentableParameterException) {
        throw (UnrepresentableParameterException) iTestResult.getThrowable();
    }
}
Also used : DefaultTestMethodDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestMethodDescriptor) TestDescriptorInternal(org.gradle.api.internal.tasks.testing.TestDescriptorInternal) TestStartEvent(org.gradle.api.internal.tasks.testing.TestStartEvent)

Example 10 with TestStartEvent

use of org.gradle.api.internal.tasks.testing.TestStartEvent in project gradle by gradle.

the class XCTestScraper method text.

@Override
public void text(String textFragment) {
    textBuilder.append(textFragment);
    if (!textFragment.endsWith(SystemProperties.getInstance().getLineSeparator())) {
        return;
    }
    String text = textBuilder.toString();
    textBuilder = new StringBuilder();
    synchronized (testDescriptors) {
        Scanner scanner = new Scanner(text).useDelimiter("'");
        if (scanner.hasNext()) {
            String token = scanner.next().trim();
            if (token.equals("Test Suite")) {
                // Test Suite 'PassingTestSuite' started at 2017-10-30 10:45:47.828
                String testSuite = scanner.next();
                if (testSuite.equals("All tests") || testSuite.equals("Selected tests") || testSuite.endsWith(".xctest")) {
                    // ignore these test suites
                    return;
                }
                String status = scanner.next();
                boolean started = status.contains("started at");
                if (started) {
                    // Using DefaultTestClassDescriptor to fake JUnit test
                    TestDescriptorInternal testDescriptor = new DefaultTestClassDescriptor(idGenerator.generateId(), testSuite);
                    processor.started(testDescriptor, new TestStartEvent(clock.getCurrentTime()));
                    testDescriptors.push(new XCTestDescriptor(testDescriptor));
                } else {
                    XCTestDescriptor xcTestDescriptor = testDescriptors.pop();
                    lastDescriptor = xcTestDescriptor.getDescriptorInternal();
                    TestDescriptorInternal testDescriptor = xcTestDescriptor.getDescriptorInternal();
                    TestResult.ResultType resultType = TestResult.ResultType.SUCCESS;
                    boolean failed = status.contains("failed at");
                    if (failed) {
                        resultType = TestResult.ResultType.FAILURE;
                    }
                    processor.completed(testDescriptor.getId(), new TestCompleteEvent(clock.getCurrentTime(), resultType));
                }
            } else if (token.equals("Test Case")) {
                // (macOS) Looks like: Test Case '-[AppTest.PassingTestSuite testCanPassTestCaseWithAssertion]' started.
                // (Linux) Looks like: Test Case 'PassingTestSuite.testCanPassTestCaseWithAssertion' started.
                String testSuiteAndCase = scanner.next();
                String[] splits = testSuiteAndCase.replace('[', ' ').replace(']', ' ').split("[. ]");
                String testSuite;
                String testCase;
                if (OperatingSystem.current().isMacOsX()) {
                    testSuite = splits[2];
                    testCase = splits[3];
                } else {
                    testSuite = splits[0];
                    testCase = splits[1];
                }
                String status = scanner.next().trim();
                boolean started = status.contains("started");
                if (started) {
                    TestDescriptorInternal testDescriptor = new DefaultTestMethodDescriptor(idGenerator.generateId(), testSuite, testCase);
                    processor.started(testDescriptor, new TestStartEvent(clock.getCurrentTime()));
                    testDescriptors.push(new XCTestDescriptor(testDescriptor));
                } else {
                    XCTestDescriptor xcTestDescriptor = testDescriptors.pop();
                    lastDescriptor = xcTestDescriptor.getDescriptorInternal();
                    TestDescriptorInternal testDescriptor = xcTestDescriptor.getDescriptorInternal();
                    TestResult.ResultType resultType = TestResult.ResultType.SUCCESS;
                    boolean failed = status.contains("failed");
                    if (failed) {
                        resultType = TestResult.ResultType.FAILURE;
                        processor.failure(testDescriptor.getId(), new Throwable(Joiner.on(TextUtil.getPlatformLineSeparator()).join(xcTestDescriptor.getMessages())));
                    }
                    processor.completed(testDescriptor.getId(), new TestCompleteEvent(clock.getCurrentTime(), resultType));
                }
            } else {
                XCTestDescriptor xcTestDescriptor = testDescriptors.peek();
                if (xcTestDescriptor != null) {
                    TestDescriptorInternal testDescriptor = xcTestDescriptor.getDescriptorInternal();
                    processor.output(testDescriptor.getId(), new DefaultTestOutputEvent(destination, text));
                    Matcher failureMessageMatcher = TEST_FAILURE_PATTERN.matcher(text);
                    if (failureMessageMatcher.find()) {
                        String testSuite = failureMessageMatcher.group(2);
                        String testCase = failureMessageMatcher.group(3);
                        String message = failureMessageMatcher.group(4);
                        if (testDescriptor.getClassName().equals(testSuite) && testDescriptor.getName().equals(testCase)) {
                            xcTestDescriptor.getMessages().add(message);
                        }
                    }
                // If no current test can be associated to the output, the last known descriptor is used.
                // See https://bugs.swift.org/browse/SR-1127 for more information.
                } else if (lastDescriptor != null) {
                    processor.output(lastDescriptor.getId(), new DefaultTestOutputEvent(destination, text));
                }
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) Matcher(java.util.regex.Matcher) TestResult(org.gradle.api.tasks.testing.TestResult) TestStartEvent(org.gradle.api.internal.tasks.testing.TestStartEvent) DefaultTestOutputEvent(org.gradle.api.internal.tasks.testing.DefaultTestOutputEvent) DefaultTestMethodDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestMethodDescriptor) TestDescriptorInternal(org.gradle.api.internal.tasks.testing.TestDescriptorInternal) DefaultTestClassDescriptor(org.gradle.api.internal.tasks.testing.DefaultTestClassDescriptor) TestCompleteEvent(org.gradle.api.internal.tasks.testing.TestCompleteEvent)

Aggregations

TestStartEvent (org.gradle.api.internal.tasks.testing.TestStartEvent)10 TestDescriptorInternal (org.gradle.api.internal.tasks.testing.TestDescriptorInternal)6 TestCompleteEvent (org.gradle.api.internal.tasks.testing.TestCompleteEvent)5 DefaultTestMethodDescriptor (org.gradle.api.internal.tasks.testing.DefaultTestMethodDescriptor)4 DefaultTestClassDescriptor (org.gradle.api.internal.tasks.testing.DefaultTestClassDescriptor)3 DefaultTestSuiteDescriptor (org.gradle.api.internal.tasks.testing.DefaultTestSuiteDescriptor)2 Scanner (java.util.Scanner)1 Matcher (java.util.regex.Matcher)1 DefaultTestDescriptor (org.gradle.api.internal.tasks.testing.DefaultTestDescriptor)1 DefaultTestOutputEvent (org.gradle.api.internal.tasks.testing.DefaultTestOutputEvent)1 TestResult (org.gradle.api.tasks.testing.TestResult)1 ITestNGMethod (org.testng.ITestNGMethod)1