Sub topic 13
Previewing and Testing with Real and Incomplete Data
This chapter assumes you can insert merge tags, set fallback values, and write basic conditional blocks in a Liquid-style template. Here you learn how to check that a personalised email works before it reaches subscribers. Most personalisation failures come from data you did not picture while building the template.
Why personalised emails need their own testing
A static email renders the same way for everyone. A personalised email is a template plus data, so it can render in as many ways as your data allows. Testing one happy-path contact proves very little.
Typical failures that reach inboxes:
- A greeting like "Hi ," or "Hi {{ customer.first_name }}," because the field was empty or the tag name was misspelled.
- A conditional that falls into the wrong branch because a value has different capitalisation ("Pro" versus "pro").
- A list that renders nothing, leaving a heading with no items under it.
- A name in capitals, or a name that is actually an email address, because it was typed that way at signup.
- Text that is far longer than expected, which breaks the layout.
Your test plan should cover the data cases, not just the template.
Preview, test send, and automated rendering
Platforms offer three levels of checking. Names differ, but the ideas are common.
| Method | What it shows | What it misses |
|---|---|---|
| Preview with a sample contact | Rendered content for one chosen contact | Email client quirks, sending-time data changes |
| Test send to your own inbox | Real rendering in real mail clients, including subject line and preheader | Many data cases, unless you send several |
| Rendering in code (for example Jinja2 or the Liquid library) | Many data cases quickly, with strict error checks | Platform-specific behaviour and filters |
Use previews for fast iteration, test sends for final visual checks, and scripted rendering when you have many branches to cover.
Some platforms mark test sends with a prefix such as "[TEST]" in the subject, and some test sends do not pull live data unless you choose a real contact. Check which one your platform does. If a test send uses placeholder data, it does not tell you how real records render.
Build a test contact set
Build a small set of test contacts that cover the data you expect in production. Keep them in a dedicated list or segment that is clearly marked as test data, so they are never included in a real send.
A useful set includes:
- Complete contact. Every field filled with normal values.
- Missing first name. The field is empty.
- Whitespace-only value. A first name containing only spaces. Some platforms treat this as non-empty, so a fallback never triggers.
- Unexpected capitalisation. "SAM" or "sam", and a plan value of "PRO".
- Unknown plan. A plan value that none of your branches name, to exercise the
elsebranch. - Very long values. A 60-character surname or company name.
- Special characters. Apostrophes, accents, ampersands, and non-Latin characters such as "Zoë", "O'Brien", or "Łukasz".
- Empty list. An order with no items.
- Large list. An order with 30 items.
- Real records. A few anonymised or consented-to copies of real production records, because real data is messier than anything you invent.
The diagram shows how a single template meets this set.
What to look for in each render
Read each rendered email as the recipient would. Look for these specific signs:
- Raw tags. Text such as
{{ customer.first_name }}in the output means the platform did not recognise the tag. This is usually a syntax or field-name error. - Orphaned punctuation. "Hi ," or "Your order of is ready" means a value rendered as empty.
- Wrong branch. Compare the plan or segment of each test contact with the content shown.
- Awkward text. "Hi SAM," or "Hi [email protected]," points to data quality problems, not template bugs. Fix the data cleaning step covered earlier, or add a filter.
- Layout. Long values wrap or push buttons off-screen, especially in the subject line, preheader, and narrow columns.
- Links. Personalised URLs, such as ones carrying an order ID, resolve to the right page and contain no unrendered tags.
Testing fallbacks and empty values properly
The fallback value is the most commonly under-tested feature. Check three cases separately:
- The field is missing from the contact record.
- The field exists but is empty.
- The field contains whitespace only.
In Liquid, default applies when the value is nil, false, or an empty string. A string of spaces is not empty, so it does not trigger the default. Platforms vary here, so test your own platform with a whitespace-only value rather than assuming.
Using strict rendering to catch silent failures
Most email platforms render a missing field as blank, which is what you want to avoid learning about from subscribers. In a scripted test, you can make missing fields raise an error instead. This Jinja2 example does that with StrictUndefined.
from jinja2 import Environment, StrictUndefined
env = Environment(undefined=StrictUndefined)
template = env.from_string("Hi {{ first_name | default('there', true) }}, your plan is {{ plan }}.")
print(template.render(first_name="", plan="Pro"))
try:
template.render(first_name="Sam")
except Exception as error:
print(type(error).__name__)The first call prints "Hi there, your plan is Pro." The true argument makes Jinja2's default apply to empty strings too, not only to undefined values. The second call omits plan, so rendering raises UndefinedError instead of sending "your plan is ." That error is the behaviour you want in a test.
Note the difference between systems. Jinja2's default filter only covers undefined values unless you pass true. Liquid's default covers nil, false, and empty strings. Because these tools share a similar look, it is easy to assume the same behaviour.
Testing conditional branches
Every branch of a conditional needs at least one contact that reaches it. Take this block.
{% if customer.plan == "pro" %}
Your Pro plan includes priority support.
{% elsif customer.plan == "free" %}
Upgrade to Pro to get priority support.
{% else %}
Explore our plans.
{% endif %}You need at least three test contacts: one with plan "pro", one with "free", and one with some other value or none. The common mistake is to test the first two and never see the else branch.
Then test the edges. A contact with plan "Pro" (capital P) will fall into else, because Liquid string comparison is case-sensitive. That is not a Liquid bug. Either normalise the data upstream, or apply a filter in the condition, for example customer.plan | downcase == "pro" in platforms that allow filters inside conditions. Check your platform, because some do not support that expression, and you may need to assign the lowercase value to a variable first.
A scripted check makes this repeatable. The sketch below uses the python-liquid library to render the same template against several plan values and print which message each one gets.
from liquid import Template
source = """{% if plan == "pro" %}Priority support.{% elsif plan == "free" %}Upgrade to Pro.{% else %}Explore our plans.{% endif %}"""
template = Template(source)
for plan in ["pro", "free", "Pro", "", "enterprise"]:
print(repr(plan), "->", template.render(plan=plan))Install the library with pip install python-liquid. The output shows that "Pro", the empty string, and "enterprise" all fall into the generic branch. Seeing this list is what prompts the decision about whether "Pro" should be handled.
Testing lists and loops
For a loop such as {% for item in order.items %}, test an empty list, a single item, and a long list. With an empty list, the loop body never runs, so a heading above it can appear with nothing beneath it. Liquid provides an else clause on for for this case. Support differs by platform, so verify it.
{% for item in order.items %}
{{ item.name }} x {{ item.quantity }}
{% else %}
Your order has no items.
{% endfor %}With a long list, check the email length. Some mail clients, Gmail among them, clip messages above a size limit, which can hide the footer and unsubscribe link. Cap the number of items shown if needed, for example with limit:10, and link to the full order.
Test the subject line and preheader
Subject lines and preheaders are rendered by the same engine, but you see them somewhere else: in the inbox list. Check them in a test send, not only in the editor preview. Look at:
- Whether the fallback reads naturally ("Sam, your order shipped" versus "there, your order shipped").
- Length after merging. Long names can push the key words off the visible part of the subject.
- Special characters rendering correctly, such as accents.
Common mistakes
- Testing only with your own record, which is usually complete and well-formed.
- Using test contacts that are not on the list or segment the live send targets, so segment rules never get exercised.
- Treating a preview as proof of correct inbox rendering.
- Changing the template after testing and sending without re-testing.
- Letting test contacts remain in the live audience.
A pre-send checklist
- Render every branch with at least one matching contact.
- Render missing, empty, and whitespace-only values for each merge tag.
- Render empty, single-item, and long lists.
- Check subject line and preheader in a test send.
- Open the test send in at least two mail clients, with one on mobile.
- Click personalised links.
- Re-run the checks after any template edit.
Exercise
A template greets with Hi {{ customer.first_name | default: "there" }},. A test contact whose first name is three spaces still renders "Hi ,". Why did the fallback not apply, and what test contact set would have caught it earlier?
Show answer
The default filter applies to nil, false, or empty strings. Three spaces is a non-empty string, so the fallback did not trigger. Cleaning the data (trimming whitespace on import or with a filter such as strip before applying the default) fixes it. A test contact set that included a whitespace-only first name, alongside missing and empty values, would have caught this before sending.
Exercise
Your template has the plan conditional shown in this chapter. You have test contacts with plans "pro" and "free". A subscriber imported with plan "PRO" gets "Explore our plans." What happened, and how would you test for it in future?
Show answer
Liquid string comparison is case-sensitive, so "PRO" does not equal "pro" and the contact falls into the else branch. Normalise the value (for example lowercasing it on import or before the comparison). To test for it, add contacts with unexpected capitalisation to the test set and confirm which branch each reaches.