-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate report file based on TestResult
- use the extent-report framework - generate report once NUnit finished generating the report - set the ignoreFailures to true by default because if an exception is thrown the task will not be finalized by generating the report; however take the flag into consideration a bit later in the workflow - added unit tests for report generation - fixed unit test to check the new behaviour
- Loading branch information
Eniko Kando
committed
Apr 16, 2019
1 parent
944d36c
commit e366846
Showing
6 changed files
with
199 additions
and
7 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
113 changes: 113 additions & 0 deletions
113
src/main/groovy/com/ullink/gradle/nunit/ReportGenerator.groovy
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.ullink.gradle.nunit | ||
|
||
import org.gradle.api.tasks.Exec | ||
|
||
class ReportGenerator extends Exec { | ||
|
||
def ExtentReportType = 'v3html' | ||
def ExtentReportDownloadUrl = 'https://github.com/extent-framework/extentreports-dotnet-cli/archive' | ||
def ExtentReportZipName = 'master.zip' | ||
def ExtentReportExecutablePath = 'extentreports-dotnet-cli-master/dist/extent.exe' | ||
|
||
@Override | ||
protected void exec() { | ||
if (isTestResultFileAvailable()) { | ||
project.logger.info("Generating the report for the Test Results..") | ||
|
||
ensureExtentReportIsAvailable() | ||
generateReports() | ||
} else { | ||
project.logger.info("There is no available Test Result file based on which the report should be generated!") | ||
} | ||
} | ||
|
||
boolean isTestResultFileAvailable() { | ||
NUnit nunit = project.tasks.nunit | ||
|
||
File testResultPath = nunit.getTestReportPath() | ||
if (!testResultPath.exists()) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
void ensureExtentReportIsAvailable() { | ||
if (!isExtentReportAvailable()) { | ||
project.logger.info "Downloading extent report..." | ||
|
||
getCacheDirForExtentReport().mkdirs() | ||
downloadExtentReport() | ||
} | ||
} | ||
|
||
boolean isExtentReportAvailable() { | ||
def extentReportCacheDir = getCacheDirForExtentReport() | ||
if (!extentReportCacheDir.exists()) { | ||
return false | ||
} | ||
|
||
def extentReportExecutable = new File(extentReportCacheDir, ExtentReportExecutablePath) | ||
if (!extentReportExecutable.exists()) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
File getCacheDirForExtentReport() { | ||
new File(new File(project.gradle.gradleUserHomeDir, 'caches'), 'extent-report') | ||
} | ||
|
||
private def generateReports() { | ||
NUnit nunit = project.tasks.nunit | ||
|
||
project.exec { | ||
commandLine = buildCommandForExtentReport(nunit.getTestReportPath(), nunit.getReportFolder()) | ||
} | ||
} | ||
|
||
def buildCommandForExtentReport(def testResultPath, def outputFolder) { | ||
def commandLineArgs = [] | ||
|
||
commandLineArgs += getExtentReportExeFile().absolutePath | ||
|
||
commandLineArgs += "-i" | ||
commandLineArgs += testResultPath | ||
|
||
commandLineArgs += "-o" | ||
commandLineArgs += outputFolder | ||
|
||
commandLineArgs += "-r" | ||
commandLineArgs += ExtentReportType | ||
|
||
commandLineArgs | ||
} | ||
|
||
File getExtentReportExeFile() { | ||
def extentReportFolder = getCacheDirForExtentReport() | ||
return new File(extentReportFolder, ExtentReportExecutablePath) | ||
} | ||
|
||
void downloadExtentReport() { | ||
def downloadedFile = new File(getTemporaryDir(), ExtentReportZipName) | ||
def extentReportDownloadUrl = getExtentReportDownloadUrl() | ||
def zipOutputDir = getCacheDirForExtentReport() | ||
|
||
project.logger.info "Downloading & Unpacking Extent Report from ${extentReportDownloadUrl}" | ||
|
||
project.download { | ||
src "$extentReportDownloadUrl" | ||
dest downloadedFile | ||
} | ||
|
||
project.copy { | ||
from project.zipTree(downloadedFile) | ||
into zipOutputDir | ||
} | ||
} | ||
|
||
String getExtentReportDownloadUrl() { | ||
// As there is no current release for extent-report we integrate the master version | ||
return "${ExtentReportDownloadUrl}/$ExtentReportZipName" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.ullink | ||
|
||
import java.nio.file.Paths | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class ReportGeneratorTest extends Specification { | ||
|
||
private static File GradleUserHomeDir = new File("path", "GradleHomeDirForTests") | ||
|
||
def "generating reports with Extent Report has the correct build arguments"() { | ||
given: | ||
def nunitReportGenerationTask = getReportGenerationTask() | ||
def testResultFile = new File("TestResult.xml") | ||
def reportOutputFolder = new File("reports/results") | ||
when: | ||
def extentReportCommandArgument = nunitReportGenerationTask.buildCommandForExtentReport(testResultFile, reportOutputFolder) | ||
then: | ||
extentReportCommandArgument == [nunitReportGenerationTask.getExtentReportExeFile().absolutePath, '-i', testResultFile, '-o', reportOutputFolder, '-r', 'v3html'] | ||
} | ||
|
||
def "extent report executable has the correct path"() { | ||
given: | ||
def nunitReportGenerationTask = getReportGenerationTask() | ||
when: | ||
def extentReportExecutable = nunitReportGenerationTask.getExtentReportExeFile() | ||
then: | ||
def pathToTheExecutable = Paths.get("path", "GradleHomeDirForTests", "caches", "extent-report", "extentreports-dotnet-cli-master", "dist", "extent.exe") | ||
extentReportExecutable.absolutePath | ||
.contains(pathToTheExecutable.normalize().toString()) | ||
} | ||
|
||
def "extent report download URL is build correctly"() { | ||
given: | ||
def nunitReportGenerationTask = getReportGenerationTask() | ||
when: | ||
def extentReportDownloadUrl = nunitReportGenerationTask.getExtentReportDownloadUrl() | ||
then: | ||
extentReportDownloadUrl == "https://github.com/extent-framework/extentreports-dotnet-cli/archive/master.zip" | ||
} | ||
|
||
|
||
def getReportGenerationTask() { | ||
def project = ProjectBuilder.builder().withGradleUserHomeDir(GradleUserHomeDir).build() | ||
project.apply plugin: 'nunit' | ||
return project.tasks.nunitReport | ||
} | ||
} |
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