-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#8] Fixed usage of ExecutionResult in result printers
- Loading branch information
1 parent
f55a645
commit f423036
Showing
2 changed files
with
18 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
* | ||
|
@@ -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.
Sorry, something went wrong. |
||
reportBuilder.set(stringBuilder); | ||
} | ||
|
||
|
@@ -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.
Sorry, something went wrong.
DmitryZajcev
|
||
} | ||
|
||
@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.
Sorry, something went wrong.
DmitryZajcev
|
||
} | ||
} |
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: "?