All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.specs2.reporter.JUnitXmlExporting.scala Maven / Gradle / Ivy

There is a newer version: 3.7
Show newest version
package org.specs2
package reporter

import specification._
import io.{FileWriter, FileSystem}
import io.Paths._
import main.{SystemProperties, Arguments}
import org.junit.runner.Description

/**
* Trait for exporting the specification as JUnit xml files
*/
trait JUnitXmlExporting extends Exporting with JUnitXmlPrinter {

  def export(implicit args: Arguments): ExecutingSpecification => ExecutedSpecification = (spec: ExecutingSpecification) => {
    val executed = spec.execute
    print(executed.name, executed.fragments)
    executed
  }

  /** the file system is used to open the file to write */
  private[specs2] lazy val fileSystem = new FileSystem {}
  /** the file writer is used to open the file to write */
  private[specs2] lazy val fileWriter = new FileWriter {}

  /**
   * the output directory is either defined by a specs2 system variable
   * or chosen as a reports directory in the standard maven "target" directory
   */
  private[specs2] lazy val outputDir: String = SystemProperties.getOrElse("junit.outDir", "target/test-reports/").absoluteDirPath

  /**
   * print a sequence of executed fragments for a given specification class into a html
   * file
   * the name of the html file is the full class name
   */
  def print(name: SpecName, fs: Seq[ExecutedFragment])(implicit args: Arguments) {
    lazy val suite = testSuite(name, fs)
    fileWriter.write(filePath(name.fullName)) { out => suite.flush(out) }
  }

  def filePath(fullSpecName: String) = outputDir + fullSpecName + ".xml"

}

object JUnitXmlExporting extends JUnitXmlExporting




© 2015 - 2024 Weber Informatics LLC | Privacy Policy