Spockã®ã¬ãã¼ãçæã¯HTML, Markdown, Asciidocã§ããããã«ã¹ã¿ã ãåºæ¥ããã ã
Groovyã®ãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ã§ããSpockã¯æ¨æºã§ã¯ã¬ãã¼ãçææ©è½ã¯ããã¾ããã å¤ãã¯Gradleã§ãã«ãããã¨ãã®xmlãhtmlãå©ç¨ãã¦ããã¨æãã¾ãã
Spockã«ã¯spock-reportã¨ããæ¡å¼µã©ã¤ãã©ãªãããããããä¾åé¢ä¿ã«è¿½å ããã ãã§ãã¹ãçµæã®ã¬ãã¼ããç¬èªã«è¿½å ã§çæã§ãã¾ãã ããããªãã¨ãHTMLã ãã§ã¯ãªãMarkdownãAsciidocã¨ãã¦çæãããã¨ãã§ãã¾ãã ã¾ããææ°ã®spock-reportã§ã¯ãã¹ãã³ã¼ãããã¬ãã¼ãã«æç« ã追å ãããã¨ãåºæ¥ãããã«ãªãã¾ããã
ä»åã¯ãããªspock-reportã®ä¾¿å©æ©è½ãããã¤ãç´¹ä»ãã¾ãã
æ¬ããã°ã§èª¬æãã¦ãããµã³ãã«ã³ã¼ãå ¨é¨å ¥ãã®spockããã³spock-reportã®ããã¸ã§ã¯ããã³ãã¬ã¼ãã¯ãã¡ãã
æ¬è¨äºã¯G* Advent Calendar 2017ã®16æ¥ç®ã«ãªãã¾ãã
G* Advent Calendar 2017 - Qiita
- æä½éã®ä½¿ãæ¹
- ã¬ãã¼ããMarkdown/Asciidocã¨ãã¦çæãã
- ãã¹ãã³ã¼ããã説æã追å ãã
æä½éã®ä½¿ãæ¹
æä½éã®HTMLã¬ãã¼ããçæããã ãã§ããã°ãSpockã§ãã¹ãã³ã¼ããå©ç¨ãã¦ããããã¸ã§ã¯ãã«ä¾åé¢ä¿ã追å ããã ãã«ãªãã¾ããï¼ãã¹ãã³ã¼ããã£ã¬ã¯ããªã src/test/groovy
é
ä¸ã§ããã°ããã ããã¨ããæãã§ããåæãªã©ã¯å¾è¿°ãã¾ãï¼
// make sure to enable jcenter() or mavenCentral() repositories { jcenter() } dependencies { testCompile( 'com.athaydes:spock-reports:1.4.0' ) { transitive = false // this avoids affecting your version of Groovy/Spock } // if you don't already have slf4j-api and an implementation of it in the classpath, add this! testCompile 'org.slf4j:slf4j-api:1.7.13' testCompile 'org.slf4j:slf4j-simple:1.7.13' }
ããslf4jãªã©ã®ãã°ã©ã¤ãã©ãªããã§ã«æå®ããã¦ãããªãæå¾ã®2è¡ã¯ä¸è¦ã§ãã
ããã§ gradle build
ã¨ãã㨠build/spock-report/index.html
ã¨ãã¦ã¬ãã¼ããã¡ã¤ã«ãçæããã¾ãããªã®ã§ãGradleãçæãã build/reports/tests/test/index.html
ã¨ã¯å¥ã«çæãããå½¢ã«ãªãã¾ãã
è¦ãç®ã¯ããã§ããã¯ã©ã·ã«ã«ã§ããè¦ãããããªãã¨ã¯æãã¾ãã
ã¬ãã¼ããMarkdown/Asciidocã¨ãã¦çæãã
ããã©ã«ãã®ã¬ãã¼ãã¯HTMLãçæãã¾ãããããã©ã«ãã§Markdownã®çæã«ã対å¿ãã¦ãã¾ãã ã¾ãããã³ãã¬ã¼ããã¡ã¤ã«ã2ã¤ç¨æãããã¨ã§Asciidocã§ã®åºåã«ã対å¿ãã¦ãã¾ãã
ä½¿ãæ¹ã¯ src/test/resources/META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties
ã¨ãããã¡ã¤ã«ãããã¸ã§ã¯ãã«è¿½å ãã¦ãè¨å®ãè¨è¿°ãã¦ããå½¢ã«ãªãã¾ãã
Markdownã§çæããããã«ã¯ãã®ãã¡ã¤ã«ã使ãã¦1è¡è¿½å ããã ãã§ãã
com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator
çæãããMarkdownã¯æ¬¡ã®ããã«ãªãã¾ãã
# Specification run results ## Specifications summary <small>Created on Sat Dec 16 08:00:48 JST 2017 by k.kobayashi</small> | Total | Passed | Failed | Feature failures | Feature errors | Success rate | Total time (ms) | |----------------|-----------------|-----------------|------------------|------------------|---------------------|-----------------| | 2 | 1 | 1 | 3 | 0 | 0.5| 108.0 | ## Specifications |Name | Features | Failed | Errors | Skipped | Success rate | Time | |------|----------|--------|--------|---------|--------------|------| | com.example.WhenReportingSpockTest | 7 | 3 | 0 | 0 | 0.5714285714285714 | 106 | | com.example.WhenUsingRawHtmlHeader | 1 | 0 | 0 | 0 | 1.0 | 2 | <small>Generated by <a href="https://github.com/renatoathaydes/spock-reports">Athaydes Spock Reports</a></small>
ãã®TemplateReportCreatorã¯ã©ã¹ã¯ãã³ãã¬ã¼ãã®ãã¡ã¤ã«ããæ¸¡ãã°åºæ¬çã«ã¯åä½ãã¾ããããã©ã«ãã§ã¯Markdownããããã¾ããããèªåã§ä¾ãã°Asciidocã®ãã³ãã¬ã¼ããç¨æããã°çæãããã¨ãã§ãã¾ãã
å
ã®ãã¡ã¤ã«ã«æ¬¡ã追è¨ãããã³ãã¬ã¼ããã¡ã¤ã«ã src/test/resources/
é
ä¸ã«ç¨æãã¾ãããã
# markdown or asciidoc com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator # asciidoc com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/spec-template.ad com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=ad com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/summary-template.ad com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.ad com.athaydes.spockframework.report.template.TemplateReportCreator.enabled=true
ããã§ã¯ src/test/resources/
é
ä¸ã« summary-template.ad
㨠spec-template.ad
ã¨ãããã¡ã¤ã«åã§ç¨æãã¾ããã
ã¬ãã¼ãã®ããããã¼ã¸ã summaryTemplateFile ã§åãã¹ãã¯ã©ã¹(Specification) ã®ãã¼ã¸ã specTemplateFile ã«ãªãã¾ãã
å®éã«ä½¿ã£ãasciidocãã¡ã¤ã«ã¯ãªãã¸ããªã«ããã¾ãã è¦ãç®ã¯ãããªãã¾ãã
= Spock Test Results // toc-title definition MUST follow document title without blank line! :toc-title: Table of Contents // numbering from here on :numbered: == Specification run results === Specifications summary [small]#created on Sat Dec 16 08:03:19 JST 2017 by k.kobayashi# .summary [options="header"] |================================================================================================================================== | Total | Passed | Failed | Feature failures | Feature errors | Success rate | Total time (ms) | 2 | 1 | 1 | 3 | 0 | 0.5| 111.0 |================================================================================================================================== === Specifications [options="header"] |=================================================================== |Name | Features | Failed | Errors | Skipped | Success rate | Time | com.example.WhenReportingSpockTest | null | null | null | null | null | null | com.example.WhenUsingRawHtmlHeader | null | null | null | null | null | null |=================================================================== <<<< include::com.example.WhenReportingSpockTest.ad[] <<<< include::com.example.WhenUsingRawHtmlHeader.ad[] [small]#generated by https://github.com/renatoathaydes/spock-reports[Athaydes Spock Reports]#
Asciidocãã°ããããincludeã§ãã¦ããã¨ããã¨ãããã§ãããï¼
Markdownã®ã¨ãã«å©ç¨ããã¦ãããã³ãã¬ã¼ããã¡ã¤ã«ã¯æ¬¡ã«ãªãã¾ããMarkdownã®ãã³ãã¬ã¼ãã夿´ãããã¨ãã«ã¯ããã®ãã¡ã¤ã«ãã³ãããã¦ãã¦æ¹å¤ããã¨ããã§ãããã
ãã¹ãã³ã¼ããã説æã追å ãã
spock-reportã§SpecificationãFeatureæ¯ã«èª¬æã追å ããæ¹æ³ã¯ä»ã¾ã§ã¯Spockã®æ©è½ã使ãããããã¾ããã§ããã
- @Narrative ã§ Specificationã®èª¬æ
- @Ignoreãªã©ã§ç¡è¦ããã¦ãããã¨ã表æ
- given, when, then, whereãªã©ã®ã©ãã«ã«ããã¹ãããã®èª¬æ
spock-reportã®ãã¼ã¸ã§ã³1.4.0ããã¯æ¬¡ã使ããããã«ãªãã¾ããã
- reportHeaderã¡ã½ããã«ããSpecificationæ¯ã®èª¬æã追å
- reportInfoã¡ã½ããã«ããfeatureæ¯ã®èª¬æã追å
ãããã¯Specificationå
ã§å®è¡ãããã¨ãæ³å®ãã¦ãã¦ãreportHeaderã¡ã½ãã㯠setupSpec
ã¡ã½ããå
ã§å®è¡ã reportInfo
ã¡ã½ããã¯featureå
ã§å®è¡ãããã¨ãæ³å®ãã¦ãã¾ãã
ä¾ãã°æ¬¡ã®ããã«ãªãã¾ãã
def setupSpec() { reportHeader """setupSpecã§reportHeaderã¡ã½ãããå¼ã³åºãã¦ãããã¨ã§ã |Specificationã®Headerã¨ãã¦æç« ãè¨è¿°ã§ãã¾ãã@Narrativeã§ååãªæ°ããã¾ããã""".stripMargin("|") } def "My feature"() { expect: reportInfo "ãã£ã¼ãã£æ¯ã®ã¡ã¢ã ã" reportInfo "2è¡ç®ãæ¸ããã" }
ããã§çæããã¬ãã¼ãã¯æ¬¡ã®ããã«ãªãã¾ãã
HTMLçã«ããã¦ã h2
ã¿ã°ã使ããããªãã¨ãããã°ãã®ã¾ã¾è¨è¿°ããå½¢ã«ãªãã¾ãã
def setupSpec() { reportHeader "<h2> h2ãããããã§è¿½å ãããã¨ãã§ãã¾ã </h2>" }
ãã¡ãããMarkdownãAsciidocã§ããè¦ãªããã ãï¼ãã£ã¦ããå ´åã«ã¯ ##
ã§è¡¨ç¾ãããã§ããããããããã«æ²¿ããããªãã³ãã¬ã¼ããç¨æããã°æå¾
ããçæçµæã«ãªãã¾ããï¼ããã©ã«ãã®Markdownã§ã¯ <h2>
ã¨æå®ããããã¨ãæ³å®ãã¦ããã®ã§ãhtmlåãè¾¼ã¿è¨è¿°ã«ãªã£ã¦ããé¨åãå¤ãã°ããã ãã§ãï¼

- ä½è : Dierk Konig,Paul King,Guillaume Laforge,Hamlet D'arcy,Cedric Champeau
- åºç社/ã¡ã¼ã«ã¼: Manning Pubns Co
- çºå£²æ¥: 2015/06/27
- ã¡ãã£ã¢: ãã¼ãã¼ããã¯
- ãã®ååãå«ãããã°ãè¦ã