From “It Opens” to “It Works”: Testing My PDF Reader with Predictable Data

2026-11-18来源 dev.toEnglish
From “It Opens” to “It Works”: Testing My PDF Reader with Predictable Data

Fix the two-page layout. Open a PDF. Check the result. Make another change. Check again.

That cycle became familiar while I was building MihirakiPDFViewer, an iPad PDF reader for books I had scanned. In Part 2, I described the work behind page spacing, right-to-left reading, and search highlight alignment.

But checking a fix with whichever book I happened to be reading had a limitation: the input kept changing. It was difficult to tell whether the next code change preserved the behavior I had just checked.

I needed test PDFs with known settings and predictable results.

This article follows how I prepared those files, asked AI to help add tests, and learned to distinguish a passing test from a broader claim that the app worked correctly.

The automated test results described here were recorded in August and September 2026 using an iPad (A16) Simulator running iOS 26.5. They are separate from my everyday testing on a physical iPad.

Start with a file you can share

My own scanned books were useful for finding problems during normal reading. They were not suitable for publishing alongside the source code so that someone else could reproduce the same checks.

I created sample documents in Google Docs, exported them as PDFs, and used a script to set different reading directions and page layouts.

The goal was to make mistakes easy to spot.

Clearly numbered pages help reveal reversed pairs. Files with the same content but different reading-direction settings make it easier to compare the app’s behavior.

Preparing test data became part of developing the app.

Right-to-left test setup with a separate cover: a four-page PDF should show page 1, then page 3 on the left and 2 on the right, then page 4.

Figure 1. Connect the input conditions to an expected sequence of views. This four-page example uses right-to-left reading, a separate cover, and the app’s STANDARD cover setting. Numbers are PDF positions starting at 1; arrows show the view sequence, not swipe direction. Schematic illustration.

Check the file, the detected settings, and the screen

The reader uses information inside the PDF to determine its reading direction and page layout.

The relevant settings are called Direction and PageLayout. A filename such as “right-to-left.pdf” does not prove that the file contains the intended values.

I needed to separate three checks:

  1. Does the PDF contain the settings I intended?
  2. Does the app recognize those settings correctly?
  3. Does the resulting page arrangement look correct on screen?

These checks answer different questions. Recognizing right-to-left metadata does not, by itself, prove that the reader opens on the correct page or puts each page on the correct side.

The test files covered two reading directions and six layout settings, giving 12 combinations. Additional files covered page pairing with and without a separate cover.

The cover examples assumed the app’s cover setting was STANDARD. The app configuration mattered as well as the file.

There was another boundary to keep clear: recognizing a continuous-layout setting in a PDF did not mean that the app reproduced that continuous viewing mode. A test of metadata recognition needed to be described as exactly that.

Give search a known answer

Finding a few results was not enough to verify search.

With a book I was reading, I usually did not know how many times a word appeared. A plausible-looking result count could hide missing or duplicate matches.

I prepared Japanese and English search PDFs containing words with known occurrence counts. Both files had 30 pages. For example:

Search term Expected matches
LOADTEST600 600
Performance Check in the English file 300

When preparing the original development article, I also checked the occurrence counts in text extracted from the PDFs.

That gave the app’s search results something concrete to match. Instead of asking whether search found “a lot” of results, I could ask whether it found the expected number.

These checks use PDFs containing searchable text. An image-only scan is a different input and should not be treated as equivalent.

A large file needs checks after opening

I also wanted to test conditions that were less likely to occur during everyday reading.

An earlier job had taught me the importance of load testing. For this project, I asked AI to create a PDF larger than 100 MB with more than 1,000 pages.

The resulting file had 1,100 pages and was about 153 MB when checked.

Opening it was only the beginning. I also wanted to know whether I could keep turning pages without a crash or an obvious stall.

The search files and the large PDF placed different demands on the reader. One tested how the reader handled many search results; the other tested opening and navigating a large document.

Three test data types and their checks: layout metadata, a 30-page searchable PDF with 600 expected LOADTEST600 hits, and a 1,100-page PDF of about 153 MB.

Figure 2. Different test files answer different questions: recognizing layout settings, finding an expected number of search matches, and navigating a large document. This diagram describes the test design, not a screenshot of test results.

Make the request specific enough to verify

After preparing the PDFs, I asked AI to add tests or check the app’s behavior with them.

The development records include requests naming the files and describing the expected output. For a right-to-left PDF with a separate cover, I specified the first page and the left/right arrangement of the following spread.

Two kinds of tests played different roles:

  • Unit tests checked results such as detected settings and search counts.
  • UI tests operated the app and checked its resulting state.

The large-PDF UI test checked the file’s size and page count, opened it, and performed 30 consecutive swipes.

Search testing included checking expected match counts and repeatedly entering search terms while turning pages.

One useful detail emerged when reviewing those tests: the test’s own checks needed improvement too.

The repeated-search UI test was strengthened to verify that the page indicator actually changed. Sending a page-turn action was not enough; the test needed evidence that navigation had occurred.

For a similar request now, I would write down three things first:

Which file should the test use? What should it do? What observable result counts as a pass?

That structure helps when asking AI to write a test. It also makes the result easier to interpret later.

A passing test has a limited scope

Some checks passed. Others did not reach a confirmed passing result.

After the 30-swipe test succeeded, I also investigated whether the slider could navigate accurately to a particular page in the 1,100-page PDF.

That work involved further changes to the test, including handling the difference between spread indices and PDF page counts, and parsing a number displayed with a thousands separator. Later runs did not reach a final passing report.

The recorded exit code alone did not establish that the app itself was at fault.

Using the same file did not make these the same test. Successful page turns did not prove accurate slider navigation.

The search results had limits too. Checking match counts and page changes did not establish pixel-perfect highlight alignment. No pixel-by-pixel image comparison was performed, and the large-PDF checks did not include numerical memory measurements.

Historical Simulator results: PDF settings were recognized, search counts and page changes were checked, and 30 consecutive swipes passed. UI layout requires a separate check. Pixel comparison was not performed, slider accuracy had no confirmed pass, and memory usage was not measured.

Figure 3. A summary of the recorded Simulator results and their limits. UI layout requires a separate check, highlight positions were not compared pixel by pixel, slider accuracy had no final confirmed pass, and memory usage was not measured.

A passing test was reassuring. I also wanted to be able to explain what that reassurance was based on.

Leave a check you can repeat

Testing began with opening my own books and seeing how the app felt. Preparing shareable PDFs gave me a more repeatable way to check specific behavior.

The useful combination was:

  1. A small input with known conditions.
  2. An action and an expected result.
  3. A record of the outcome, including anything still unverified.

A few clearly numbered pages can make a layout problem easier to discuss. A search term with a known count can turn a vague impression into a checkable result.

AI helped create the data and the test code. I still needed to decide which conditions mattered, what counted as success, and how far the results supported my conclusions.

What small test files or fixtures have helped you catch regressions in your own projects?

Source and code: Adapted and reorganized from my Japanese development article on Qiita. The source code and test data are available on GitHub.

The repository includes later changes. The results discussed here describe the historical development records and Simulator checks identified above.

AI disclosure: I used AI assistance to organize and draft this English article and to help create the explanatory diagrams. The development experiences and test results described here are based on my records.

原文:https://www.a8q9.cn/en/article/from-it-opens-to-it-works-testing-my-pdf-reader-with-predictable-data-fb9a43.html

相关文章