diff --git a/src/main/java/com/github/houbb/junitperf/core/jupiter/context/PerfConfigContext.java b/src/main/java/com/github/houbb/junitperf/core/jupiter/context/PerfConfigContext.java index 9d21282..e8fc032 100644 --- a/src/main/java/com/github/houbb/junitperf/core/jupiter/context/PerfConfigContext.java +++ b/src/main/java/com/github/houbb/junitperf/core/jupiter/context/PerfConfigContext.java @@ -52,7 +52,7 @@ public PerfConfigContext(ExtensionContext context) { public List getAdditionalExtensions() { return Collections.singletonList( (TestInstancePostProcessor) (testInstance, context) -> { - final Class clazz = testInstance.getClass(); + final Class clazz = testInstance.getClass(); // Group test contexts by test class ACTIVE_CONTEXTS.putIfAbsent(clazz, new ArrayList<>()); diff --git a/src/main/java/com/github/houbb/junitperf/model/evaluation/EvaluationContext.java b/src/main/java/com/github/houbb/junitperf/model/evaluation/EvaluationContext.java index fc98d01..b658278 100644 --- a/src/main/java/com/github/houbb/junitperf/model/evaluation/EvaluationContext.java +++ b/src/main/java/com/github/houbb/junitperf/model/evaluation/EvaluationContext.java @@ -12,6 +12,7 @@ import com.github.houbb.junitperf.support.builder.EvaluationResultBuilder; import org.apiguardian.api.API; +import org.junit.jupiter.api.DisplayName; import java.io.Serializable; import java.lang.reflect.Method; @@ -44,6 +45,12 @@ public class EvaluationContext implements Serializable { */ private final String methodName; + /** + * 方法展示名称 + * @see org.junit.jupiter.api.DisplayName + */ + private final DisplayName displayName; + /** * 开始时间 */ @@ -76,6 +83,7 @@ public EvaluationContext(final Object testInstance, this.testInstance = testInstance; this.testMethod = testMethod; this.methodName = testMethod.getName(); + this.displayName = testMethod.getAnnotation(DisplayName.class); this.startTime = startTime; } @@ -139,6 +147,15 @@ public Method getTestMethod() { return testMethod; } + /** + * 获取显示名称 + * 有指定显示名称的话,使用显示名称 + * @see DisplayName + */ + public String getDisplayName() { + return displayName == null ? methodName : displayName.value(); + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/resources/templates/report.ftl b/src/main/resources/templates/report.ftl index e3a1b96..32dbd09 100644 --- a/src/main/resources/templates/report.ftl +++ b/src/main/resources/templates/report.ftl @@ -190,11 +190,11 @@ <#assign active = (context_index==0) ? string("active", "")> <#if context.evaluationResult.isSuccessful()>
  • - ${context.methodName} + ${context.displayName}
  • <#else>
  • - ${context.methodName} + ${context.displayName}
  • @@ -207,7 +207,7 @@ <#list contextData as context>
    - ${context.methodName} + ${context.displayName}
    @@ -219,7 +219,7 @@ var data = google.visualization.arrayToDataTable([ ['Percentile', 'Latency', {role: "tooltip"}], <#list 1..100 as i> - [ ${i}, ${context.statisticsCalculator.getLatencyPercentile(i, milliseconds)} , "${i}% of executions ≤ ${context.statisticsCalculator.getLatencyPercentile(i, milliseconds)}ms"], + [ ${i}, ${context.statisticsCalculator.getLatencyPercentile(i, milliseconds)?c} , "${i}% of executions ≤ ${context.statisticsCalculator.getLatencyPercentile(i, milliseconds)}ms"], ]); var options = {