Skip to content

Commit

Permalink
[#8] Fixed usage of ExecutionResult in result printers
Browse files Browse the repository at this point in the history
  • Loading branch information
Pheodor Paramonov authored and vvolverine committed Nov 25, 2018
1 parent f55a645 commit f423036
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void illuminateTestCaseStart(TestCaseStartedEvent startEvent) {
@EventListener
public void illuminateTestCaseFinish(TestCaseFinishedEvent finishEvent) {
LOGGER.debug("Test case finished: '{}' with status {}",
finishEvent.getTestCase().getName(), finishEvent.getExecutionResult());
finishEvent.getTestCase().getName(), finishEvent.getExecutionResult().getStatus());
}

@EventListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package com.griddynamics.qa.sprimber.lifecycle;

import com.griddynamics.qa.sprimber.engine.model.ExecutionResult;
import com.griddynamics.qa.sprimber.lifecycle.model.executor.testcase.TestCaseFinishedEvent;
import com.griddynamics.qa.sprimber.lifecycle.model.executor.testcase.TestCaseStartedEvent;
import com.griddynamics.qa.sprimber.lifecycle.model.executor.testhook.TestHookFinishedEvent;
Expand All @@ -34,9 +35,10 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import org.springframework.core.NamedThreadLocal;

import java.util.Arrays;
import java.util.Optional;

/**
* This is a helper class that able to print shor summary after each scenario to info log level
* This is a helper class that able to print short summary after each scenario to info log level
* By default this bean not configured automatically,
* use property {@code sprimber.configuration.summary.printer.enable} to enable it
*
Expand All @@ -46,13 +48,14 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class TestCaseSummaryPrinter {

private static final Logger LOGGER = LoggerFactory.getLogger(TestCaseSummaryPrinter.class);
private static final String EMPTY_STRING = "";
private ThreadLocal<StringBuilder> reportBuilder = new NamedThreadLocal<>("Testcase report builder");

@EventListener
public void illuminateTestCaseStart(TestCaseStartedEvent startEvent) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("\n\n");
stringBuilder.append(String.format("Test Case Started: %s", startEvent.getTestCase().getName()));
stringBuilder.append(String.format("Test Case Completed: %s", startEvent.getTestCase().getName()));

This comment has been minimized.

Copy link
@DmitryZajcev

DmitryZajcev Nov 26, 2018

Why do we need to specify test case state right at the beginning?
It's really sounds strange - it doesn't matter what will happen with my test case - I'll see Completed state of it.
Second - it's already confusing that method that is responsible for test case start handling - applies final state message to the test case.
Can we use something state-independent like a simple - "Test Case: "?

reportBuilder.set(stringBuilder);
}

Expand All @@ -71,14 +74,24 @@ public void illuminateTestStepFinish(TestStepFinishedEvent finishEvent) {
stringBuilder.append(String.format(" %s", finishEvent.getTestStep().getStepAction().getActionType()));
stringBuilder.append(String.format(" %s", finishEvent.getTestStep().getActualText()));
stringBuilder.append(String.format(" %s", Arrays.toString(finishEvent.getTestStep().getStepArguments())));
stringBuilder.append(String.format(" (%s) ", finishEvent.getExecutionResult()));
stringBuilder.append(String.format(" (%s) ", finishEvent.getExecutionResult().getStatus()));
stringBuilder.append(String.format(" (%s) ", getExceptionMessageIfAny(finishEvent.getExecutionResult())));

This comment has been minimized.

Copy link
@DmitryZajcev

DmitryZajcev Nov 26, 2018

It's not a clear solution when you are still doing some actions when condition for the actions is not satisfied.
Please refactor it via separate method where you can check if applicable and only then append additional text to the stroingBuilder.

}

@EventListener
public void illuminateTestHookFinish(TestHookFinishedEvent finishEvent) {
StringBuilder stringBuilder = reportBuilder.get();
stringBuilder.append("\n");
stringBuilder.append(String.format(" %s from:", finishEvent.getHookDefinition().getActionType()));
stringBuilder.append(String.format(" %s of scope", finishEvent.getHookDefinition().getActionType()));
stringBuilder.append(String.format(" %s from:", finishEvent.getHookDefinition().getActionScope()));
stringBuilder.append(String.format(" %s", finishEvent.getHookDefinition().getMethod()));
}

private String getExceptionMessageIfAny(ExecutionResult executionResult) {
return executionResult.getOptionalError().map(this::buildExceptionMessage).orElse(EMPTY_STRING);
}

private String buildExceptionMessage(Throwable throwable) {
return Optional.ofNullable(throwable.getMessage()).orElse(throwable.getClass().getName());

This comment has been minimized.

Copy link
@DmitryZajcev

DmitryZajcev Nov 26, 2018

In case if message is presented - don't we want to show exception class name as well?

}
}

0 comments on commit f423036

Please sign in to comment.