From 7e2d45e86e652b3ebc4a99a1914a5b28a188e769 Mon Sep 17 00:00:00 2001 From: yangchao269 Date: Mon, 19 Jul 2021 10:46:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=93=8D=E5=BA=94=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=B6=85=E8=BF=871=E7=A7=92=E6=97=B6=EF=BC=8Cftl=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E8=BE=93=E5=87=BA=E6=95=B0=E5=AD=97=E4=BC=9A=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E9=80=97=E5=8F=B7=E5=A6=82=EF=BC=9A1000.00=20=3D>html?= =?UTF-8?q?=201,000.00=E3=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这样js脚本会报错,解决办法:使用freemarker内部函数?c 输出纯数字。 资料: https://freemarker.apache.org/docs/ref_builtins_number.html#ref_builtin_c https://blog.csdn.net/sayoko06/article/details/80272007 --- src/main/resources/templates/report.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/report.ftl b/src/main/resources/templates/report.ftl index e3a1b96..4f719f0 100644 --- a/src/main/resources/templates/report.ftl +++ b/src/main/resources/templates/report.ftl @@ -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 = { From d96b36865ec6e20e1384d82023cd167052636523 Mon Sep 17 00:00:00 2001 From: yangchao269 Date: Mon, 19 Jul 2021 11:43:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?html=20=E6=8A=A5=E5=91=8A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=20@DisplayName=20=E6=B3=A8=E8=A7=A3=E3=80=82?= =?UTF-8?q?=E6=9C=89=E6=8C=87=E5=AE=9A=E6=98=BE=E7=A4=BA=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E7=9A=84=E8=AF=9D=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/jupiter/context/PerfConfigContext.java | 2 +- .../model/evaluation/EvaluationContext.java | 17 +++++++++++++++++ src/main/resources/templates/report.ftl | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) 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 4f719f0..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}