It might seem surprisingly to store validation rules in Excel and use them in automated test. But it has the advantage of enabling non-programmers to create tests which can be executed by programs created by programmers.
The Excel files can be used by the Java-API of PDFUnit and by the PDFUnit-Monitor. The monitor is also created for non-programmers. Separate documentation exists for the monitor and can be accessed at http://www.pdfunit.com/de/download/index.html. A short description can be found in chapter 8: “PDFUnit-Monitor”.
A detailed description of the structure of an Excel file and the available test methods is given in chapter 10: “Validation Constraints in Excel Files”. That chapter is not necessary for understanding how the Excel files are used, so you can read it later.
There is only one method for using Excel files:
// Validation method, using Excel-based constraints: .compliesWith().constraints(excelRules)
This method can be applied to a single document, multiple documents, or all documents in a folder:
// Validation of one, many or all PDF documents: AssertThat.document(filename) .compliesWith() .constraints(excelRules) AssertThat.eachDocument() .inFolder(folder) .compliesWith() .constraints(excelRules) AssertThat.eachDocument(files) .compliesWith() .constraints(excelRules)
In the next example, a PDF document is validated against constraints which are located in the Excel file 'din5008-formA_letter-portrait.xls':
@Test public void singleDocumentCompliesWithExcelRules() throws Exception { String filename = "documentUnderTest.pdf"; String rulesAsExcelFile = PATH_TO_RULES + "din5008-formA_letter-portrait.xls"; PDFValidationConstraints excelRules = new PDFValidationConstraints(rulesAsExcelFile); AssertThat.document(filename) .compliesWith() .constraints(excelRules) ; }
If the test fails, an error message shows all constraint violations. A test does not stop after the first detected error.
The structure of an Excel file is described in chapter 10: “Validation Constraints in Excel Files”.