Each test begins with the tag <testcase name=".." />
,
containing its name in the attribute name=".."
.
Then the tag <assertThat testDocument=".." />
is nested, which
defines which PDF file should be tested.
You can place other tags inside of <assertThat>
for various test scopes,
e.g. visible content, fonts, layout.
The following examples show the basic syntax for different types of tests. You will replace “XXX” with real terms which are listed at the end of this chapter.
<!-- Instantiating a test document for specific tests: --> <testcase name="test111"> <assertThat testDocument="documentUnderTest.pdf"> <hasXXX> <!-- Switch to one of many test scopes. --> ... <!-- Use test scope specific tags here. --> </hasXXX> </assertThat> </testcase>
<!-- Comparing a test document with a master document: --> <testcase name="test222"> <assertThat testDocument="documentUnderTest.pdf" masterDocument="masterDocument.pdf" > <haveSameXXX /> <!-- Comparing many parts of a PDF. --> </assertThat> </testcase>
<!-- Using encrypted PDF documents: --> <testcase name="test333"> <assertThat testDocument="documentUnderTest.pdf" testPassword="test-password" > ... </assertThat> </testcase>
<!-- Set a test to 'ignore': --> <testcase name="test555" ignore="No suitable document available" > <assertThat testDocument="documentUnderTest.pdf" > ... </assertThat> </testcase>
It is possible to write a test for a given set of PDF documents.
Such tests starts with the method <assertThatEachDocument>
:
<testcase name="textInMultipleDocuments"> <assertThatEachDocument> <pdf name="&pdfdir;/multipleDocuments/document_en.pdf" /> <pdf name="&pdfdir;/multipleDocuments/document_es.pdf" /> <pdf name="&pdfdir;/multipleDocuments/document_de.pdf" /> <hasText on="FIRST_PAGE" > <containing>28.09.2014</containing> <containing>XX-123</containing> </hasText> </assertThatEachDocument> </testcase>
The chapter 5: “Tests with Multiple Documents” describes more about tests on multiple documents.
Tests that expect an exception have to declare that with the attribute errorExpected="YES"
:
<testcase name="hasSignature_DocumentNotSigned" errorExpected="YES" > <assertThat testDocument="signed/notSigned.pdf"> <hasSignature name="Signature2" /> </assertThat> </testcase>
The following list gives a complete overview of the test scopes of PDFUnit. The link behind each tag points to the relevant chapter. The list is sorted alphabetically.
<!-- Each of the following tags opens a new test scope: --> <areBothForFastWebView /> 4.20: “Further Comparisons” <asRenderedPage /> 3.17: “Layout - Entire PDF Pages” <containsImage /> 3.13: “Images in PDF Documents” <containsOneOfTheseImages /> 3.13: “Images in PDF Documents” <hasAnyAction /> 3.2: “Actions” <hasAuthor /> 3.7: “Document Properties” <hasBookmark /> 3.4: “Bookmarks and Named Destinations” <hasBookmarks /> 3.4: “Bookmarks and Named Destinations” <hasChainedAction /> 3.2: “Actions” <hasCloseAction /> 3.2: “Actions” <hasCreationDate /> 3.6: “Dates” <hasCreationDateAfter /> 3.6: “Dates” <hasCreationDateBefore /> 3.6: “Dates” <hasCreator /> 3.6: “Dates” <hasEmbeddedFile /> 3.3: “Attachments” <hasEmbeddedFileContent /> 3.3: “Attachments” <hasEncryptionLength /> 3.21: “Passwords” <hasField /> 3.10: “Form Fields” <hasFields /> 3.10: “Form Fields” <hasFont /> 3.9: “Fonts” <hasFonts /> 3.9: “Fonts” <hasFormat /> 3.12: “Format” <hasImportDataAction /> 3.2: “Actions” <hasJavaScript /> 3.14: “JavaScript” <hasJavaScriptAction /> 3.2: “Actions” <hasKeywords /> 3.7: “Document Properties” <hasLaunchAction /> 3.2: “Actions” <hasLayer /> 3.16: “Layers” <hasLayers /> 3.16: “Layers” <hasLessPages /> 3.20: “Page Numbers as Objectives” <hasLocale /> 3.15: “Language” <hasLocalGotoAction /> 3.2: “Actions” <hasModificationDate /> 3.6: “Dates” <hasModificationDateAfter /> 3.6: “Dates” <hasModificationDateBefore /> 3.6: “Dates” <hasMorePages /> 3.20: “Page Numbers as Objectives” <hasNamedAction /> 3.2: “Actions” <hasNamedDestination /> 3.4: “Bookmarks and Named Destinations” ... continued
... continuation: <hasNoAuthor /> 3.7: “Document Properties” <hasNoCreationDate /> 3.6: “Dates” <hasNoCreator /> 3.7: “Document Properties” <hasNoKeywords /> 3.7: “Document Properties” <hasNoLocale /> 3.15: “Language” <hasNoModificationDate /> 3.6: “Dates” <hasNoProducer /> 3.7: “Document Properties” <hasNoProperty /> 3.7: “Document Properties” <hasNoSubject /> 3.7: “Document Properties” <hasNoText /> 3.25: “Text” <hasNoTitle /> 3.7: “Document Properties” <hasNoXFAData /> 3.30: “XFA Data” <hasNoXMPData /> 3.31: “XMP Data” <hasNumberOfXXX /> 3.19: “Number of PDF Elements” <hasOCG /> 3.16: “Layers” <hasOCGs /> 3.16: “Layers” <hasOpenAction /> 3.2: “Actions” <hasOwnerPassword /> 3.21: “Passwords” <hasPermission /> 3.22: “Permissions” <hasPrintAction /> 3.2: “Actions” <hasProducer /> 3.7: “Document Properties” <hasProperty /> 3.7: “Document Properties” <hasRemoteGotoActionTo /> 3.2: “Actions” <hasResetFormAction /> 3.2: “Actions” <hasSaveAction /> 3.2: “Actions” <hasSignature /> 3.23: “Signatures and Certificates” <hasSignatures /> 3.23: “Signatures and Certificates” <hasSignedSignatureFields /> 3.23: “Signatures and Certificates” <hasSubject /> 3.7: “Document Properties” <hasSubmitFormAction /> 3.2: “Actions” <hasText /> 3.25: “Text” <hasTitle /> 3.7: “Document Properties” <hasTrappingInfo /> 3.28: “Trapping Info” <hasUnsignedSignatureFields /> 3.23: “Signatures and Certificates” <hasURIAction /> 3.2: “Actions” <hasUserPassword /> 3.21: “Passwords” <hasVersion /> 3.29: “Version Info” <hasXFAData /> 3.30: “XFA Data” <hasXMPData /> 3.31: “XMP Data” <haveSame... /> 4.1: “Overview” <isCertified /> 3.5: “Certified PDF” <isLinearizedForFastWebView /> 3.8: “Fast Web View” <isSigned /> 3.23: “Signatures and Certificates” <isTagged /> 3.24: “Tagged Documents” ... (end of list)
PDFUnit is continuously being improved and we keep the manul up to date. Wishes and requests for new functions are appreciated. Please send them to request[at]pdfunit.com.