Giter Site home page Giter Site logo

xsltest's Introduction

XSLTest: XSLT easy stylesheet testing

Requirements:

  • An XSLT 2 processor, such as Saxon.
  • A web browser to view the test reports.

Overview

XSLTest lets you test XSLT transforms and functions using a mix of XSLT code, XSLTest elements that define assertions and test suites and embedded HTML documentation.

An XSLTest suite is an XSLT stylesheet with named templates that generate HTML and also contain XSLTest elements.

The XSLTest framework acts as a compiler: the xsltest.xslt stylesheet translates a test suite into a stylesheet that performs the assertions and generates results in XML format. XSLTest's report.xslt stylesheet translates the results into an HTML report.

XSLTest also provides a stylesheet, test-abort-build.xslt, that fails if the results XML contain any test failures. This is useful for aborting the build when tests fail.

Example tests written with XSLTest can be found here: https://github.com/npryce/courseware-html/tree/master/tests

Test Suite Structure and XML Namespaces

XSLTest elements are defined in the namespace http://www.natpryce.com/xsltest/1.0.

The entry-point to a test suite is a named XSLT template. For example:

<xsl:stylesheet version="2.0"
                xmlns="http://www.w3.org/1999/xhtml" 
                xmlns:html="http://www.w3.org/1999/xhtml" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fn="http://www.w3.org/2005/xpath-functions" 
                xmlns:test="http://www.natpryce.com/xsltest/1.0">

  <xsl:import href="mycode.xslt"/>
  
  <xsl:template name="mycode-tests">
      <test:suite>
          <h1>Tests for My Code</h1>
          
          ... assertions and suites go here ...

      </test:suite>
  </xsl:template>
</xsl:stylesheet>

Example Makefile Rules

The following example Makefile rules implement the XSLTest processing pipeline.

build/testing/%.xslt: src/%-test.xslt
	@mkdir -p $(dir $@)
	saxon -xsl:$(XSLTEST_HOME)/xsltest.xslt -s:$< -o:$@

build/testing/results.xml: $(XSLT_TESTS:tests/%.xslt=build/testing/%.xslt) $(XSLT)
	saxon -xsl:build/testing/all-tests.xslt -it:all-tests -o:$@
    
build/testing/report.html: build/testing/results.xml
	saxon -xsl:$(XSLTEST_HOME)/report.xslt -s:$< -o:$@

# Avoid saxon's slow startup if we can say for sure that no tests failed
check: build/testing/report.html
	@if grep -q -m 1 'result="failed"' build/testing/results.xml; then \
		saxon -xsl:$(XSLTEST_HOME)/test-abort-build.xslt -s:build/testing/results.xml; \
	fi

The rules assume that:

  • The variable XSLTEST_HOME refers to the directory containing the XSLTest stylesheets.
  • The test suite files all have the suffix -test.xslt and are in the src/ directory alongside the code under test.
  • Output is generated into a scratch directory named build/testing.
  • There is a single root test suite, named all-tests.xslt, that imports all the other test suites in the test directory.

xsltest's People

Contributors

npryce avatar

Stargazers

Godrichp avatar Steve Freeman avatar  avatar James Abley avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.