From 289d1116857075dbc053aec3f527258a6b22543a Mon Sep 17 00:00:00 2001 From: Adam Chudzik Date: Thu, 22 Jan 2015 01:03:01 +0100 Subject: [PATCH 1/2] Resolves marcingrzejszczak/gradle-test-profiler#7: 'Module' column added to report --- test_profiling.gradle | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/test_profiling.gradle b/test_profiling.gradle index 5a6c5f0..78aabdc 100644 --- a/test_profiling.gradle +++ b/test_profiling.gradle @@ -19,6 +19,7 @@ class TestExecutionResult { */ @Immutable(knownImmutableClasses = [TestExecutionResult]) class ReportRow { + String module TestExecutionResult testExecutionResult Double testClassExecutionTime } @@ -26,45 +27,48 @@ class ReportRow { Set testExecutionResults = [] as Set allprojects { + project.ext { testprofiling_separator = '\t' - testprofiling_headers = "test class name${testprofiling_separator}test name${testprofiling_separator}test execution time in [s]${testprofiling_separator}test class execution time in [s]\n" + testprofiling_headers = "module${testprofiling_separator}test class name${testprofiling_separator}test name${testprofiling_separator}test execution time in [s]${testprofiling_separator}test class execution time in [s]\n" testprofiling_comparator = { ReportRow o1, ReportRow o2 -> - if (o1.testClassExecutionTime <=> o2.testClassExecutionTime != 0) { - return o2.testClassExecutionTime <=> o1.testClassExecutionTime + if (o1.testExecutionResult.testExecutionTime <=> o2.testExecutionResult.testExecutionTime != 0) { + return o2.testExecutionResult.testExecutionTime <=> o1.testExecutionResult.testExecutionTime } if (o1.testExecutionResult.testClassName <=> o2.testExecutionResult.testClassName != 0) { return o2.testExecutionResult.testClassName <=> o1.testExecutionResult.testClassName } - if (o1.testExecutionResult.testExecutionTime <=> o2.testExecutionResult.testExecutionTime != 0) { - return o2.testExecutionResult.testExecutionTime <=> o1.testExecutionResult.testExecutionTime + if (o1.testExecutionResult.testName <=> o2.testExecutionResult.testName != 0) { + return o2.testExecutionResult.testName <=> o1.testExecutionResult.testName + } + if (o1.testClassExecutionTime <=> o2.testClassExecutionTime != 0) { + return o2.testClassExecutionTime <=> o1.testClassExecutionTime } - return o2.testExecutionResult.testName <=> o1.testExecutionResult.testName + return o2.module <=> o1.module + } testprofiling_dir = "${project.buildDir.absolutePath}/reports/test_profiling" - testprofiling_filename = "testsProfiling.csv" + testprofiling_filename = "testsProfile.csv" testprofiling_fullPath = "${testprofiling_dir}/${testprofiling_filename}" testprofiling_mergedTestProfilingSummaryDir = "${project.rootDir.absolutePath}/build/reports/test_profiling" testprofiling_mergedTestProfilingSummary = "${testprofiling_mergedTestProfilingSummaryDir}/summary.csv" } test { + doFirst { + testExecutionResults = [] as Set + } + addTestListener(new TestListener() { @Override - void beforeSuite(TestDescriptor suite) { - - } + void beforeSuite(TestDescriptor suite) { } @Override - void afterSuite(TestDescriptor suite, TestResult result) { - - } + void afterSuite(TestDescriptor suite, TestResult result) { } @Override - void beforeTest(TestDescriptor testDescriptor) { - - } + void beforeTest(TestDescriptor testDescriptor) { } @Override void afterTest(TestDescriptor testDescriptor, TestResult result) { @@ -82,7 +86,7 @@ allprojects { Map classExecutionTime = testExecutionResults.groupBy { it.testClassName }.collectEntries { [it.key, it.value.sum { it.testExecutionTime } as Double] } as Map - String testExecutionResult = testExecutionResults.collect { new ReportRow(it, classExecutionTime[it.testClassName]) } + String testExecutionResult = testExecutionResults.collect { new ReportRow(project.path, it, classExecutionTime[it.testClassName]) } .sort(testprofiling_comparator) .collect(rowFromReport()).join('\n') report << testExecutionResult @@ -104,13 +108,13 @@ task testsProfileSummaryReport << { Set reportRows = new TreeSet(project.ext.testprofiling_comparator) fileContent.split('\n').each { String[] row = it.split(project.ext.testprofiling_separator) - reportRows << new ReportRow(new TestExecutionResult(row[0], row[1], row[2] as Double), row[3] as Double) + reportRows << new ReportRow(row[0], new TestExecutionResult(row[1], row[2], row[3] as Double), row[4] as Double) } mergedTestProfilingSummary << reportRows.collect(rowFromReport()).join('\n') } Closure rowFromReport() { return { ReportRow reportRow -> - "${reportRow.testExecutionResult.testClassName}${testprofiling_separator}${reportRow.testExecutionResult.testName}${testprofiling_separator}${reportRow.testExecutionResult.testExecutionTime}${testprofiling_separator}${reportRow.testClassExecutionTime}" + "${reportRow.module}${testprofiling_separator}${reportRow.testExecutionResult.testClassName}${testprofiling_separator}${reportRow.testExecutionResult.testName}${testprofiling_separator}${reportRow.testExecutionResult.testExecutionTime}${testprofiling_separator}${reportRow.testClassExecutionTime}" } } From 55227a67ad31a63510798780eefde0f5d17431ea Mon Sep 17 00:00:00 2001 From: Adam Chudzik Date: Thu, 22 Jan 2015 01:03:48 +0100 Subject: [PATCH 2/2] Resolves marcingrzejszczak/gradle-test-profiler#15: classExecutionTime is now rounded to the 3rd place after the comma --- test_profiling.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_profiling.gradle b/test_profiling.gradle index 78aabdc..0c3ed87 100644 --- a/test_profiling.gradle +++ b/test_profiling.gradle @@ -84,8 +84,9 @@ allprojects { report.delete() report << testprofiling_headers Map classExecutionTime = testExecutionResults.groupBy { it.testClassName }.collectEntries { - [it.key, it.value.sum { it.testExecutionTime } as Double] + [it.key, (it.value.sum { it.testExecutionTime } as Double).round(3)] } as Map + String testExecutionResult = testExecutionResults.collect { new ReportRow(project.path, it, classExecutionTime[it.testClassName]) } .sort(testprofiling_comparator) .collect(rowFromReport()).join('\n')