Chapter 2. Quickstart

Quickstart

Let's assume you have a some programs that generates PDF documents and you want to make sure that the programs do what they should. Further expect that your test document has exactly one page and contains the greeting Thank you for using our services. and the value 30.34 Euro for the total bill. Then it's easy to check these requirements with PDFUnit:

<testcase name="hasOnePage_en">
  <assertThat testDocument="quickstart/quickstartDemo_en.pdf">
    <hasNumberOfPages>1</hasNumberOfPages>
  </assertThat>
</testcase>

<testcase name="hasGreeting_en">
  <assertThat testDocument="quickstart/quickstartDemo_en.pdf">
    <hasText on="LAST_PAGE">
      <containing>Thank you for using our services.</containing>
    </hasText>
  </assertThat>
</testcase>

<testcase name="hasExpectedCharge_en">
  <assertThat testDocument="quickstart/quickstartDemo_en.pdf">
    <hasText on="FIRST_PAGE">
      <inClippingArea upperLeftX="172" upperLeftY="178" width="20" height="9">
        <containing>29.89 Euro</containing> <!-- This value is intentionally false. -->
      </inClippingArea>
    </hasText>
  </assertThat>
</testcase>

The typical JUnit report shows the success or the failures with meaningful messages:

That's it. The following chapters describe the features, typical test scenarios and problems when testing PDF documents.