ru.yandex.qatools.allure.events.TestCaseStartedEvent Java Examples

The following examples show how to use ru.yandex.qatools.allure.events.TestCaseStartedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureRunListener.java    From allure-cucumberjvm with Apache License 2.0 6 votes vote down vote up
@Override
public void testStarted(Description description) throws IllegalAccessException {

    if (description.isTest()) {
        String methodName = extractMethodName(description);
        TestCaseStartedEvent event = new TestCaseStartedEvent(getSuiteUid(description), methodName);
        event.setTitle(methodName);

        Collection<Annotation> annotations = new ArrayList<>();
        for (Annotation annotation : description.getAnnotations()) {
            annotations.add(annotation);
        }

        AnnotationManager am = new AnnotationManager(annotations);
        am.update(event);
        getLifecycle().fire(event);
    }
}
 
Example #2
Source File: AllureTestListenerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void skipTestFireTestCaseStartedEvent() {
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);
    when(testResult.getTestContext().getSuite().getName()).thenReturn(DEFAULT_SUITE_NAME);
    when(testResult.getTestContext().getCurrentXmlTest().getName()).thenReturn(DEFAULT_XML_TEST_NAME);
    when(testResult.getTestClass().getName()).thenReturn(DEFAULT_CLASS_NAME);
    when(testResult.getMethod().getMethodName()).thenReturn(DEFAULT_TEST_NAME);
    doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);

    String uid = UUID.randomUUID().toString();
    when(testContext.getAttribute("SUITE_UID")).thenReturn(uid);
    testngListener.onTestSkipped(testResult);

    String suiteUid = testngListener.getSuiteUid(testContext);
    verify(allure).fire(eq(withExecutorInfo(new TestCaseStartedEvent(suiteUid, DEFAULT_TEST_NAME).withLabels(
            AllureModelUtils.createTestSuiteLabel(DEFAULT_SUITE_NAME),
            AllureModelUtils.createTestGroupLabel(DEFAULT_XML_TEST_NAME),
            AllureModelUtils.createTestClassLabel(DEFAULT_CLASS_NAME),
            AllureModelUtils.createTestMethodLabel(DEFAULT_TEST_NAME)))));
}
 
Example #3
Source File: AllureTestListener.java    From allure1 with Apache License 2.0 6 votes vote down vote up
private void addPendingMethods(ITestContext iTestContext) {
    for (ITestNGMethod method : iTestContext.getExcludedMethods()) {
        if (method.isTest() && !method.getEnabled() && isInActiveGroup(method, iTestContext)) {
            Description description = new Description().withValue(method.getDescription());
            String suiteUid = getSuiteUid(iTestContext);
            TestCaseStartedEvent event = new TestCaseStartedEvent(suiteUid, method.getMethodName());
            if (description.getValue() != null) {
                event.setDescription(description);
            }
            Annotation[] annotations = method.getConstructorOrMethod().getMethod().getAnnotations();
            AnnotationManager am = new AnnotationManager(annotations);
            am.setDefaults(method.getInstance().getClass().getAnnotations());
            am.update(event);
            getLifecycle().fire(event);
            getLifecycle().fire(new TestCasePendingEvent());
            fireFinishTest();
        }
    }
}
 
Example #4
Source File: AnnotationManagerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCombinedValuesUpdateTestCaseStartedEvent() throws Exception {
    AnnotationManager annotationManager = setAnnotationManager("combinedMethod");

    TestCaseStartedEvent event = new TestCaseStartedEvent("some.uid", "some.name");
    annotationManager.update(event);
   
    assertThat(event.getTitle(), is(nullValue()));
    Description description = annotationManager.getDescription();
    assertThat(description, is(nullValue()));
    assertThat(event.getLabels(), hasItems(
            createStoryLabel("default.story"), 
            createFeatureLabel("default.feature"),
            createSeverityLabel(SeverityLevel.CRITICAL),
            createIssueLabel("initial.issue")
    ));
}
 
Example #5
Source File: AnnotationManagerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultValuesUpdateTestCaseStartedEvent() throws Exception {
    AnnotationManager annotationManager = setAnnotationManager("defaultMethod");

    TestCaseStartedEvent event = new TestCaseStartedEvent("some.uid", "some.name");
    annotationManager.update(event);

    assertThat(event.getTitle(), is(nullValue()));
    Description description = annotationManager.getDescription();
    assertThat(description, is(nullValue()));
    assertThat(event.getLabels(), hasItems(
            createStoryLabel("default.story"), 
            createFeatureLabel("default.feature"),
            createIssueLabel("default.issue")
    ));
}
 
Example #6
Source File: AnnotationManagerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateTestCaseStartedEvent() throws Exception {
    TestCaseStartedEvent event = new TestCaseStartedEvent("some.uid", "some.name");
    annotationManager.update(event);

    assertThat(event.getTitle(), equalTo("some.title"));

    Description description = annotationManager.getDescription();
    assertThat(description.getValue(), is("some.description"));
    assertThat(description.getType(), is(DescriptionType.TEXT));

    assertThat(event.getLabels(), hasItems(
            createStoryLabel("some.story"), 
            createFeatureLabel("some.feature"),
            createSeverityLabel(SeverityLevel.BLOCKER),
            createIssueLabel("some.simple.issue"),
            createIssueLabel("some.nested.issue.1"),
            createIssueLabel("some.nested.issue.2")
    ));        
}
 
Example #7
Source File: AnnotationManagerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialValuesUpdateTestCaseStartedEvent() throws Exception {
    AnnotationManager annotationManager = setAnnotationManager("simpleMethod");

    TestCaseStartedEvent event = new TestCaseStartedEvent("some.uid", "some.name");
    annotationManager.update(event);

    assertThat(event.getTitle(), equalTo("some.title"));

    Description description = annotationManager.getDescription();
    assertThat(description.getValue(), is("some.description"));
    assertThat(description.getType(), is(DescriptionType.TEXT));

    assertThat(event.getLabels(), hasItems(
            createStoryLabel("some.story"), 
            createFeatureLabel("some.feature"),
            createSeverityLabel(SeverityLevel.BLOCKER),
            createIssueLabel("some.simple.issue"),
            createIssueLabel("some.nested.issue.1"),
            createIssueLabel("some.nested.issue.2"),
            createTestLabel("test.case.id")
    ));
}
 
Example #8
Source File: AllureTestListenerTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void parametrizedTest() {
    double doubleParameter = 10.0;
    String stringParameter = "string";
    String anotherStringParameter = "anotherString";
    String nullValueParameter = null;
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);
    when(testResult.getTestContext().getSuite().getName()).thenReturn(DEFAULT_SUITE_NAME);
    when(testResult.getTestContext().getCurrentXmlTest().getName()).thenReturn(DEFAULT_XML_TEST_NAME);
    when(testResult.getTestClass().getName()).thenReturn(DEFAULT_CLASS_NAME);
    when(testResult.getMethod().getMethodName()).thenReturn(DEFAULT_TEST_NAME);
    when(testResult.getParameters()).thenReturn(new Object[]{doubleParameter, stringParameter, anotherStringParameter, nullValueParameter});

    doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);

    String uid = UUID.randomUUID().toString();
    when(testContext.getAttribute("SUITE_UID")).thenReturn(uid);
    testngListener.onTestStart(testResult);

    String suiteUid = testngListener.getSuiteUid(testContext);
    String testName = String.format("%s[%s,%s,%s,%s]",
            DEFAULT_TEST_NAME, Double.toString(doubleParameter), stringParameter, anotherStringParameter, nullValueParameter);
    verify(allure).fire(eq(withExecutorInfo(new TestCaseStartedEvent(suiteUid, testName).withLabels(
            AllureModelUtils.createTestSuiteLabel(DEFAULT_SUITE_NAME),
            AllureModelUtils.createTestGroupLabel(DEFAULT_XML_TEST_NAME),
            AllureModelUtils.createTestClassLabel(DEFAULT_CLASS_NAME),
            AllureModelUtils.createTestMethodLabel(DEFAULT_TEST_NAME)))));

    ArgumentCaptor<AddParameterEvent> captor = ArgumentCaptor.forClass(AddParameterEvent.class);
    verify(allure, times(3)).fire(captor.capture());

    Iterator<AddParameterEvent> addParameterEvents = captor.getAllValues().iterator();
    assertParameterEvent("doubleParameter", doubleParameter + "", addParameterEvents.next(), false);
    assertParameterEvent("valueFromAnnotation", anotherStringParameter, addParameterEvents.next(), true);
    assertParameterEvent("valueFromAnnotation", "null", addParameterEvents.next(), true);
    assertFalse(addParameterEvents.hasNext());
}
 
Example #9
Source File: AllureMarathonRunListener.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void testStarted(Description description) {
    TestCaseStartedEvent event = new TestCaseStartedEvent(getSuiteUid(description), getTestName());

    SeverityLevel severityLevel = SeverityLevel.NORMAL;
    Properties testProperties = getTestProperties();
    String severity = testProperties.getProperty("severity");
    if (severity != null) {
        severityLevel = SeverityLevel.fromValue(severity);
    }
    event.getLabels().add(AllureModelUtils.createSeverityLabel(severityLevel));

    String desc = testProperties.getProperty("description");
    if (desc != null) {
        String dType = "text";
        if (desc.startsWith("html:")) {
            dType = "html";
            desc = desc.substring(5);
        } else if (desc.startsWith("markdown:")) {
            dType = "markdown";
            desc = desc.substring(9);
        }
        event.setDescription(
                new ru.yandex.qatools.allure.model.Description().withType(DescriptionType.fromValue(dType)).withValue(desc));
    }

    String id = testProperties.getProperty("id");
    if (id != null) {
        event.getLabels().add(AllureModelUtils.createTestLabel(id));
    }

    Path testPath = Paths.get(testProperties.getProperty("path", ""));
    addGroups(issues, event.getLabels(), testPath, LabelName.ISSUE);
    addGroups(features, event.getLabels(), testPath, LabelName.FEATURE);
    addGroups(stories, event.getLabels(), testPath, LabelName.STORY);
    getLifecycle().fire(event);
}
 
Example #10
Source File: AllureTestListenerTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void skipTestFiredEventsOrder() {
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getThrowable()).thenReturn(new NullPointerException());
    when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);

    doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);

    testngListener.onTestSkipped(testResult);

    InOrder inOrder = inOrder(allure);
    inOrder.verify(allure).fire(isA(TestCaseStartedEvent.class));
    inOrder.verify(allure).fire(isA(TestCaseCanceledEvent.class));
    inOrder.verify(allure).fire(isA(TestCaseFinishedEvent.class));
}
 
Example #11
Source File: AllureTestListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
private void createConfigEvent(ITestResult iTestResult) {
    String description = iTestResult.getMethod().getDescription();
    if (description == null || description.isEmpty()) {
        description = getConfigMethodType(iTestResult).getName();
    }
    String suiteUid = getSuiteUid(iTestResult.getTestContext());
    TestCaseStartedEvent event = new TestCaseStartedEvent(suiteUid, iTestResult.getName());
    event.setDescription(new Description().withValue(description));
    AnnotationManager am = new AnnotationManager(getMethodAnnotations(iTestResult));
    am.setDefaults(getClassAnnotations(iTestResult));
    am.update(event);
    getLifecycle().fire(event);
}
 
Example #12
Source File: AllureTestListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestStart(ITestResult iTestResult) {
    ITestNGMethod method = iTestResult.getMethod();
    String testSuiteLabel = iTestResult.getTestContext().getSuite().getName();
    String testGroupLabel = iTestResult.getTestContext().getCurrentXmlTest().getName();
    String testClassLabel = iTestResult.getTestClass().getName();
    String testMethodLabel = method.getMethodName();
    String suitePrefix = getCurrentSuitePrefix(iTestResult);
    String testName = getName(iTestResult);
    startedTestNames.add(testName);
    testName = testName.replace(suitePrefix, "");

    String invoc = getMethodInvocationsAndSuccessPercentage(iTestResult);
    Description description = new Description().withValue(method.getDescription());
    String suiteUid = getSuiteUid(iTestResult.getTestContext());
    TestCaseStartedEvent event = new TestCaseStartedEvent(suiteUid, testName + invoc).withLabels(
            AllureModelUtils.createTestSuiteLabel(testSuiteLabel),
            AllureModelUtils.createTestGroupLabel(testGroupLabel),
            AllureModelUtils.createTestClassLabel(testClassLabel),
            AllureModelUtils.createTestMethodLabel(testMethodLabel));
    if (description.getValue() != null) {
        event.setDescription(description);
    }
    AnnotationManager am = new AnnotationManager(getMethodAnnotations(iTestResult));
    am.setDefaults(getClassAnnotations(iTestResult));
    am.update(event);

    getLifecycle().fire(event);

    if (AllureConfig.newInstance().areTestNgParametersEnabled()) {
        fireAddParameterEvents(iTestResult);
    }
}
 
Example #13
Source File: AllureRunListenerTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartedTest() throws Exception {
    Description description = mock(Description.class);
    when(description.getAnnotations()).thenReturn(Collections.<Annotation>emptyList());
    when(description.getMethodName()).thenReturn("some.method.name");

    doReturn("some.uid").when(runListener).getSuiteUid(description);
    runListener.testStarted(description);

    inOrder(allure).verify(allure).fire(eq(new ClearStepStorageEvent()));
    inOrder(allure).verify(allure).fire(eq(
            withExecutorInfo(new TestCaseStartedEvent("some.uid", "some.method.name"))
    ));
}
 
Example #14
Source File: AllureRunListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
public void startFakeTestCase(Description description) {
    String uid = getSuiteUid(description);

    String name = description.isTest() ? description.getMethodName() : description.getClassName();
    TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name);
    AnnotationManager am = new AnnotationManager(description.getAnnotations());
    am.update(event);

    fireClearStepStorage();
    getLifecycle().fire(event);
}
 
Example #15
Source File: AllureRunListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Override
public void testStarted(Description description) {
    TestCaseStartedEvent event = new TestCaseStartedEvent(getSuiteUid(description), description.getMethodName());
    AnnotationManager am = new AnnotationManager(description.getAnnotations());

    am.update(event);

    fireClearStepStorage();
    getLifecycle().fire(event);
}
 
Example #16
Source File: AllureLifecycleTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
public TestCaseResult fireTestCaseStart(String uid) {
    Allure.LIFECYCLE.fire(new TestCaseStartedEvent(uid, "some.case.name"));
    TestCaseResult testCase = Allure.LIFECYCLE.getTestCaseStorage().get();
    assertNotNull(testCase);
    assertThat(testCase.getName(), is("some.case.name"));
    return testCase;
}
 
Example #17
Source File: AllureLifecycleTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void supportForConcurrentUseOfChildThreadsTestCases() throws Exception {
    final int threads = 20;
    final int testCases = 1000;

    final Allure lifecycle = Allure.LIFECYCLE;

    String suiteUid = UUID.randomUUID().toString();
    fireTestSuiteStart(suiteUid);
    fireTestCaseStart(suiteUid);

    ExecutorService service = Executors.newFixedThreadPool(threads);

    final List<Callable<Object>> tasks = new ArrayList<>();

    final String uid = UUID.randomUUID().toString();
    lifecycle.fire(new TestSuiteStartedEvent(uid, uid));
    for (int i = 0; i < threads; i++) {
        tasks.add(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                for (int i = 0; i < testCases; i++) {
                    lifecycle.fire(new TestCaseStartedEvent(uid, "test-case"));
                    lifecycle.fire(new StepFinishedEvent());
                }
                return "";
            }
        });
    }

    List<Future<Object>> futures = service.invokeAll(tasks);
    for (Future<Object> future : futures) {
        future.get();
    }

    assertThat(lifecycle.getTestSuiteStorage().get(uid).getTestCases(), hasSize(threads * testCases));
}
 
Example #18
Source File: Allure.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Process TestCaseStartedEvent. New testCase will be created and added
 * to suite as child.
 *
 * @param event to process
 */
public void fire(TestCaseStartedEvent event) {
    //init root step in parent thread if needed
    stepStorage.get();

    TestCaseResult testCase = testCaseStorage.get();
    event.process(testCase);

    synchronized (TEST_SUITE_ADD_CHILD_LOCK) {
        testSuiteStorage.get(event.getSuiteUid()).getTestCases().add(testCase);
    }

    notifier.fire(event);
}
 
Example #19
Source File: AnnotationManager.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Add information about host and thread to specified test case started event
 *
 * @param event given event to update
 * @return updated event
 */
public static TestCaseStartedEvent withExecutorInfo(TestCaseStartedEvent event) {
    event.getLabels().add(createHostLabel(getHostname()));
    event.getLabels().add(createThreadLabel(format("%s.%s(%s)",
                    ManagementFactory.getRuntimeMXBean().getName(),
                    Thread.currentThread().getName(),
                    Thread.currentThread().getId())
    ));
    return event;
}
 
Example #20
Source File: AnnotationManager.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets into specified {@link ru.yandex.qatools.allure.events.TestCaseStartedEvent}
 * information from Allure annotations.
 *
 * @param event to change
 */
public void update(TestCaseStartedEvent event) {
    if (isTitleAnnotationPresent()) {
        event.setTitle(getTitle());
    }

    if (isDescriptionAnnotationPresent()) {
        event.setDescription(getDescription());
    }

    if (isSeverityAnnotationPresent()) {
        event.getLabels().add(createSeverityLabel(getSeverity()));
    }

    if (isIssueAnnotationPresent()) {
        event.getLabels().add(createIssueLabel(getIssueKey()));
    }

    if (isIssuesAnnotationPresent()) {
        for (String issueKey : getIssueKeys()) {
            event.getLabels().add(createIssueLabel(issueKey));
        }
    }

    if (isTestCaseIdAnnotationPresent()) {
        event.getLabels().add(createTestLabel(getTestCaseId()));
    }

    event.getLabels().addAll(getStoryLabels());
    event.getLabels().addAll(getFeatureLabels());
    withExecutorInfo(event);
}
 
Example #21
Source File: ListenersNotifier.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke to tell listeners that an test case started event processed
 */
@Override
public void fire(TestCaseStartedEvent event) {
    for (LifecycleListener listener : listeners) {
        try {
            listener.fire(event);
        } catch (Exception e) {
            logError(listener, e);
        }
    }
}
 
Example #22
Source File: AllureRunListener.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
public void startFakeTestCase(Description description) throws IllegalAccessException {
    String uid = getSuiteUid(description);

    String name = description.isTest() ? description.getMethodName() : description.getClassName();
    TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name);
    event.setTitle(name);
    AnnotationManager am = new AnnotationManager(description.getAnnotations());
    am.update(event);

    getLifecycle().fire(event);
}
 
Example #23
Source File: AllureMarathonRunListener.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void startFakeTestCase(Description description) {
    String uid = getSuiteUid(description);

    String name = description.isTest() ? getTestName() : getSuiteName(description);
    TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name);
    AnnotationManager am = new AnnotationManager(description.getAnnotations());
    am.update(event);

    fireClearStepStorage();
    getLifecycle().fire(event);
}
 
Example #24
Source File: ListenersNotifierTest.java    From allure1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testcaseStartedEventTest() throws Exception {
    allure.fire(new TestCaseStartedEvent("", ""));
    assertThat(listener.get(SimpleListener.EventType.TESTCASE_STARTED_EVENT), is(1));
}
 
Example #25
Source File: SimpleListener.java    From allure1 with Apache License 2.0 4 votes vote down vote up
@Override
public void fire(TestCaseStartedEvent event) {
    counts.get(EventType.TESTCASE_STARTED_EVENT).incrementAndGet();
}
 
Example #26
Source File: LifecycleListener.java    From allure1 with Apache License 2.0 2 votes vote down vote up
/**
 * Called when a test case started
 */
public void fire(TestCaseStartedEvent event) { // NOSONAR
}