plugin extensions unit testing dita-ot · jason fox (fiware foundation) the views presented in this...

18
Unit Testing DITA-OT Plugin Extensions Jason Fox (FIWARE Foundation)

Upload: others

Post on 21-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Unit Testing DITA-OT Plugin Extensions

Jason Fox (FIWARE Foundation)

Page 2: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

1

Disclaimer

Page 3: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

New Employer - FIWARE Foundation

2

Page 4: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

3

New Employer - FIWARE Foundation

Open Source Friendly - Everything is available on GitHub:

Website: fiware.org

@FIWARE on Twitter

https://github.com/jason-fox/fox.jason.unit-test

Page 5: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Why Unit Testing?

▪ Validate that it does what you want

▪ Check that you haven’t broken something else

▪ Essential safety net for refactoring

Why not unit testing?

▪ Writing tests is difficult

▪ No support tools

▪ Spend more time debugging the tests than the code

4

Page 6: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Why Code Coverage?

▪ Validate your tests are comprehensive

▪ Check that no dead code is left in the code base

▪ Maintain standards

Why Profiling?

▪ Check where bottlenecks occur

5

Page 7: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Demonstration

▪ UNIT TESTING

▪ CODE COVERAGE

▪ ANT PROFILING

6

Page 8: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Unit Test Report and Coverage Report

7

Page 9: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Profiling Report

8

Page 10: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

9

Deep Dive - Unit Testing

▪ build-init▪ unit-test.init▪ generate-fixtures▪ unit-test▪ coverage.report▪ unit-test.report

Page 11: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

10

Anatomy of a Test Suite Directory

▪ Series of named sub directories:

• One Test = One Dir

▪ Essential file in root

• bootstrap.xml

▪ Other Special Files• coverage.xml• test.properties• disabled.txt

Page 12: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

11

Anatomy of a Unit Test

▪ Standard DITA-OT inputs• document.ditamap • *.dita files

▪ Output becomes Test expectation• expected.html• expected.fo• etc

▪ build.xml defines the flowof the test by calling ANT tasks defined in the plugin

Page 13: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

12

Simplifying the Unit Tests

▪ cfg - simplifies the Output• attributes.xml - Attributes to ignore in the output• colors.xml - Switches from HEX to readable names• fonts.xml - Switches from your fonts to placeholders (e.g. Monospace)

▪ resource - simplifies the Input - see API Reference• Compare-Output• Contains-Text• Exec-HTML5• Exec-PDF• Exec-Transtype• Get-HMTL-Article• Get-PDF-Article

Page 14: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

13

Writing your own Unit Tests

▪ Copy an existing test from the samples in the plugin to get a simple PDF or HTML output

▪ Update the expectation.html/fo Volkswagening test.copy parameter

▪ Run build.xml directly to get verbose output (useful when debugging)

▪ Repeat...

Page 15: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Deep Dive - Code Coverage

▪ Instrument▪ Adds <xsl:message> to each

decision point▪ Unique ID based on number of

preceding nodes▪ Create an empty coverage.xml

file with line numbers and IDs

▪ Coverage Report▪ When unit tests are run, IDs are

piped to output.▪ coverage-report target updates

number of hits▪ XSL transform to HTML and

Cobertura

14

Page 16: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Integration - Travis CI + Coveralls

▪ Use any CI to run tests

▪ coverage.xml is Cobertura-like output

▪ Use standard pom.xml to read file and upload online

▪ Can track coverage over time

▪ Legitimately display and Badges

15

Page 17: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

16

Deep Dive - Profiling

Antro▪ Existing ANT listener task▪ Add to classpath and as a listener

Antro UI ▪ GUI can be invoked as a Java Jar▪ Add to classpath and run Java

Page 18: Plugin Extensions Unit Testing DITA-OT · Jason Fox (FIWARE Foundation) The views presented in this workshop are my own and do not necessarily reflect the views of the FIWARE Foundation

Thank you!

http://fiware.orgFollow @FIWARE on Twitter