Skip to content

Commit

Permalink
UnitTestMixin: added getTestName(ITestResult) + footer prints test name
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Mar 2, 2020
1 parent a45fb2e commit c87d0a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Expand Up @@ -49,7 +49,7 @@ public Logger logger() {
public String contextName() {
ITestResult context = TEST_CONTEXT_THREAD_LOCAL.get();
return context != null
? getClass().getSimpleName() + "." + context.getMethod().getMethodName()
? getTestName(context)
: getClass().getSimpleName();
}

Expand Down
Expand Up @@ -36,6 +36,15 @@ public interface UnitTestMixin {
*/
@NotNull String contextName();

/**
* Returns test name (as "class-simple-name.method") from {@link ITestResult}.
*/
@NotNull
default String getTestName(ITestResult context) {
return context.getTestClass().getRealClass().getSimpleName()
+ "." + context.getMethod().getMethodName();
}

/**
* Returns short test name - typically just a method name (without class).
* See also {@link #contextName()} if class name is required.
Expand All @@ -55,8 +64,9 @@ default void displayTestTitle(String testName) {

default void displayDefaultTestFooter(ITestResult testResult) {
long testMsDuration = testResult.getEndMillis() - testResult.getStartMillis();
System.out.println(TEST_OUT_FOOTER_PREFIX + " FINISHED in " + testMsDuration + " ms" + TEST_OUT_FOOTER_SUFFIX);
logger().info(TEST_LOG_PREFIX + " FINISHED in " + testMsDuration + " ms" + TEST_LOG_SUFFIX);
String testName = getTestName(testResult);
System.out.println(TEST_OUT_FOOTER_PREFIX + testName + " FINISHED in " + testMsDuration + " ms" + TEST_OUT_FOOTER_SUFFIX);
logger().info(TEST_LOG_PREFIX + testName + " FINISHED in " + testMsDuration + " ms" + TEST_LOG_SUFFIX);
}

/**
Expand Down

0 comments on commit c87d0a0

Please sign in to comment.