Search in sources :

Example 1 with SoftAssertionError

use of org.vividus.softassert.model.SoftAssertionError in project vividus by vividus-framework.

the class AllureStoryReporterTests method mockSoftAssertionError.

private AssertionFailedEvent mockSoftAssertionError(KnownIssue knownIssue) {
    SoftAssertionError softAssertionError = new SoftAssertionError(null);
    softAssertionError.setKnownIssue(knownIssue);
    AssertionFailedEvent assertionFailedEvent = mock(AssertionFailedEvent.class);
    when(assertionFailedEvent.getSoftAssertionError()).thenReturn(softAssertionError);
    return assertionFailedEvent;
}
Also used : AssertionFailedEvent(org.vividus.softassert.event.AssertionFailedEvent) SoftAssertionError(org.vividus.softassert.model.SoftAssertionError)

Example 2 with SoftAssertionError

use of org.vividus.softassert.model.SoftAssertionError in project vividus by vividus-framework.

the class AbstractCloudTestStatusManagerTests method shouldUpdateCloudTestStatusToFailure.

@SuppressWarnings("unchecked")
@Test
void shouldUpdateCloudTestStatusToFailure() throws UpdateCloudTestStatusException {
    SoftAssertionError assertionError = mock(SoftAssertionError.class);
    when(webDriverProvider.isWebDriverInitialized()).thenReturn(true);
    when(assertionError.isKnownIssue()).thenReturn(false);
    statusManager.setCloudTestStatusToFailure(new AssertionFailedEvent(assertionError));
    statusManager.setCloudTestStatusToFailure(new AssertionFailedEvent(assertionError));
    statusManager.setCloudTestStatusToFailure(new AssertionFailedEvent(assertionError));
    statusManager.updateCloudTestStatus(new BeforeWebDriverQuitEvent());
    verify(statusManager).updateCloudTestStatus(FAILED);
    verify(testContext, times(5)).get(any(Class.class), any(Supplier.class));
    verify(testContext).remove(any(Class.class));
    assertThat(logger.getLoggingEvents(), is(empty()));
}
Also used : BeforeWebDriverQuitEvent(org.vividus.selenium.event.BeforeWebDriverQuitEvent) Supplier(java.util.function.Supplier) AssertionFailedEvent(org.vividus.softassert.event.AssertionFailedEvent) SoftAssertionError(org.vividus.softassert.model.SoftAssertionError) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SoftAssertionError

use of org.vividus.softassert.model.SoftAssertionError in project vividus by vividus-framework.

the class SoftAssert method verify.

@Override
public void verify() throws VerificationError {
    AssertionCollection assertionCollection = getAssertionCollection();
    try {
        List<SoftAssertionError> assertionErrors = assertionCollection.getAssertionErrors();
        if (assertionErrors.isEmpty()) {
            LOGGER.atInfo().log(() -> formatter.getPassedVerificationMessage(assertionCollection.getAssertionsCount()));
        } else {
            String errorsMessage = formatter.getErrorsMessage(assertionErrors, true);
            LOGGER.atError().addArgument(formatter.getFailedVerificationMessage(assertionErrors, assertionCollection.getAssertionsCount())).addArgument(errorsMessage).log("{}{}");
            throw new VerificationError(errorsMessage, assertionErrors);
        }
    } finally {
        assertionCollection.clear();
    }
}
Also used : VerificationError(org.vividus.softassert.exception.VerificationError) AssertionCollection(org.vividus.softassert.model.AssertionCollection) SoftAssertionError(org.vividus.softassert.model.SoftAssertionError)

Example 4 with SoftAssertionError

use of org.vividus.softassert.model.SoftAssertionError in project vividus by vividus-framework.

the class SoftAssert method recordAssertionError.

protected void recordAssertionError(KnownIssue issue, String message, Throwable cause) {
    SoftAssertionError assertionError = new SoftAssertionError(new AssertionError(message, cause));
    assertionError.setKnownIssue(issue);
    getAssertionCollection().addFailed(assertionError);
    eventBus.post(new AssertionFailedEvent(assertionError));
    if (assertionError.isFailTestSuiteFast()) {
        failTestFastHandler.failTestSuiteFast();
    }
    if (failTestCaseFast && !assertionError.isKnownIssue() || assertionError.isFailTestCaseFast()) {
        failTestFastHandler.failTestCaseFast();
    }
}
Also used : SoftAssertionError(org.vividus.softassert.model.SoftAssertionError) AssertionFailedEvent(org.vividus.softassert.event.AssertionFailedEvent) SoftAssertionError(org.vividus.softassert.model.SoftAssertionError)

Example 5 with SoftAssertionError

use of org.vividus.softassert.model.SoftAssertionError in project vividus by vividus-framework.

the class AssertionFormatter method getErrorsMessage.

@Override
public String getErrorsMessage(List<SoftAssertionError> errors, boolean includeStackTraceInformation) {
    Writer writer = new StringWriter();
    try (PrintWriter printWriter = new PrintWriter(writer)) {
        int index = 1;
        for (SoftAssertionError error : errors) {
            if (index == 1 || !includeStackTraceInformation) {
                printWriter.println();
            }
            printWriter.print(index++);
            printWriter.print(") ");
            AssertionError assertionError = error.getError();
            if (includeStackTraceInformation) {
                if (stackTraceFilter != null) {
                    stackTraceFilter.printFilteredStackTrace(assertionError, printWriter);
                } else {
                    assertionError.printStackTrace(printWriter);
                }
            } else {
                printWriter.print(assertionError.getMessage());
            }
        }
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) SoftAssertionError(org.vividus.softassert.model.SoftAssertionError) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) SoftAssertionError(org.vividus.softassert.model.SoftAssertionError) PrintWriter(java.io.PrintWriter)

Aggregations

SoftAssertionError (org.vividus.softassert.model.SoftAssertionError)20 Test (org.junit.jupiter.api.Test)11 AssertionFailedEvent (org.vividus.softassert.event.AssertionFailedEvent)9 VerificationError (org.vividus.softassert.exception.VerificationError)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)5 KnownIssue (org.vividus.softassert.model.KnownIssue)4 Supplier (java.util.function.Supplier)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 ReportPortal (com.epam.reportportal.service.ReportPortal)1 SaveLogRQ (com.epam.ta.reportportal.ws.model.log.SaveLogRQ)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 LinkedHashSet (java.util.LinkedHashSet)1 BeforeOrAfterFailed (org.jbehave.core.failures.BeforeOrAfterFailed)1 Failure (org.vividus.model.Failure)1 RunningScenario (org.vividus.model.RunningScenario)1 RunningStory (org.vividus.model.RunningStory)1 BeforeWebDriverQuitEvent (org.vividus.selenium.event.BeforeWebDriverQuitEvent)1