Module: L1-M04 · Duration: ~195 min (estimate, including the independent exercise) · Previous: L01 · Next: L03 - Exploratory testing charters for AI features
1. Introduction
Real users do not type the sample questions. They send empty messages, paste a whole page of logs, type without diacritics, mix English into Vietnamese, mistype order numbers. Some inputs look exactly the same on screen but are different to a program.
This lesson teaches two classic testing techniques, equivalence partitioning and boundary value analysis, applied to a chatbot. It also teaches a group of defects that matters especially for Vietnamese: Unicode normalization.
One important idea runs through the lesson: many defects with unusual input are not in the model but in the application code around the model, such as the length check, regexes, the keyword router, filters. That is the part you can test deterministically.
2. Learning objectives
- Partition a chatbot's input into equivalence classes, and choose boundary values for a length limit.
- Explain NFC and NFD, and why two strings that look the same can give different results.
- Generate negative and boundary inputs with
lab/inputs.py, including invisible characters. - Distinguish behaviour the contract specifies from behaviour it does not yet specify, and record the latter as a question for the product owner.
- Build a boundary pack and correctly mark the cases that the current build violates.
3. Prerequisites and tools
- L01: oracles and the contract C1-C12.
- L1-M01-L02: tokens. Length in characters differs from length in tokens.
4. Concepts
4.1 Equivalence partitioning and boundary values
Equivalence partitioning: divide the input into groups that the system is expected to handle the same way. Test one representative per group instead of every value. For message length under C6 (1-2000 characters after trimming whitespace at both ends):
| Class | Example | Expected |
|---|---|---|
| Empty | "" |
clarify |
| Whitespace only | " ", "\n\t" |
clarify |
| Valid | 1 to 2000 characters | Handled normally |
| Too long | over 2000 characters | too_long, no silent truncation |
Boundary values: defects tend to sit on the borders between classes, especially off-by-one errors when a
developer writes >= instead of >. For the 2000 limit, test 1999, 2000, 2001. The clause says
"1-2000", which means 2000 is valid.
Everyday example. A bus is free for children under 1.3 m. Someone checking the rule should measure one child of 1.29 m, one of exactly 1.3 m and one of 1.31 m. Measuring ten more children of 1.1 m adds nothing, because they are all in the same class. The risky case is the child of exactly 1.3 m: does "under 1.3 m" include them?
Good vs bad.
| Weak choice of values | Good choice |
|---|---|
| Lengths of 500, 1000 and 3000 characters | 1999, 2000, 2001 (the boundary), plus one representative of each other class: empty, whitespace only |
Why: 500 and 1000 are in the same class, and no value sits exactly where >= differs from >. The demo in
§8.1 shows that only the value 2000 catches v1's off-by-one defect.
4.2 Unicode: NFC, NFD and invisible characters
The letter "ủ" can be stored in two ways:
- NFC (precomposed form): a single code point
U+1EE7. - NFD (decomposed form):
u+ the combining hook aboveU+0309.
The Unicode Standard treats these two forms as canonically equivalent (canonical equivalence), that is, the
same abstract character [R1]. They look identical on screen. But to a program:
"hoàn tiền" == nfd("hoàn tiền") is False, and the lengths are 9 versus 12. Code that compares strings,
searches for keywords or counts length without normalizing first behaves differently with the two forms.
Text in NFD form can come from copying between applications or from some input methods. For a Vietnamese product, NFD is a separate equivalence class that needs testing.
Invisible characters: the zero-width space U+200B does not show on screen but is still in the string. The
Tags block (U+E0000-U+E007F) is described by Unicode as "invisible format control characters" [R2].
Invisible characters can break keyword searches or regexes, and L04 will show that they also help to get past
filters.
Everyday example. The precomposed "ủ" is like a rubber stamp carved with the letter and its mark in one piece. The decomposed form is like writing "u" and then sticking a separate hook-shaped mark on top. On paper they look the same, but a machine that counts the pieces gets 1 and 2. A zero-width space is like a transparent thread between two pages: nobody sees it, but the pages no longer stick together.
Worked example: a length counted wrongly. C6 counts the length after treating NFC and NFD as the same. A
message of 1990 characters in NFC form is valid. What about the same message in NFD form? Save this as
vd_l02.py in the lab folder and run python vd_l02.py:
from lab import inputs
from lab.shopeasy import make_assistant
bot = make_assistant("v1")
text = "à" * 1980 + " hoàn tiền" # 1990 characters in NFC
for name, message in (("NFC", text), ("NFD", inputs.nfd(text))):
print(name, len(message), bot.reply(message)["intent"])
Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions give identical output):
NFC 1990 refund_policy
NFD 3973 too_long
- In NFD form, each "à" is 2 code points (
a+U+0300), so 1980 letters "à" become 3960 code points. - The tail " hoàn tiền" has 13 code points in NFD form. Total: 3960 + 13 = 3973.
- v1 counts code points before normalizing, sees 3973 > 2000 and returns
too_long. - The customer typed only 1990 characters, and C6 says the Unicode form does not change the result. This is a bug, in the same class as the NFD defect of the returns flow in §8.1. The extra exercise in §9.2 turns C6 into code to catch the whole class.
4.3 Language: no diacritics, mixed, slang
- No diacritics: many people type "toi muon hoan tien" on their phones.
- Mixed language (code-switching): "refund policy là gì?" is very common.
- Regional words and abbreviations: "ko", "hông", "e" (em). Lesson L05 tests this group.
For each group, the first question is: does the contract specify it? C5 specifies the reply language for a mixed message. The contract says nothing about Vietnamese without diacritics. In that case the tester's job is to record the observation and ask the product owner, not to decide on the product's behalf.
Good vs bad. The same observation, written two ways:
| Weak note | Good note |
|---|---|
| "Bug: the bot does not understand Vietnamese without diacritics." | "Issue (question for the product owner): 'toi muon hoan tien' gives out_of_scope on v1. The contract says nothing about Vietnamese without diacritics. Should the product understand this way of typing?" |
Why: the good note has the exact input, the build and the result, and says clearly that it is a question because the contract does not specify the behaviour. The weak note decides on the product owner's behalf.
4.4 Malformed input
- Near-miss order numbers:
SE10O1(the letter O instead of the digit 0),SE 1001(with a space). - All capitals, emoji, line breaks.
Expectations must come from the contract. C2 says order numbers are case-insensitive, so se1002 must work.
For SE10O1, the product must not guess; it must ask for the order number again.
Everyday example. A bank teller receives a transfer slip on which one digit of the account number is
smudged. They must not guess the digit; they ask the customer again. A chatbot that meets SE10O1 is in the
same position: asking for the order number again is far safer than giving the status of a different order. On
v1, SE 1001 (with a space) also gets clarify; in the demo in §8.1, so does SE10O1.
4.5 Limits of the API itself
The 2000-character limit belongs to the ShopEasy application. The API underneath has its own limits. For
example, the Claude documentation on 2026-10-31 lists a 1M-token context window for Claude Opus 5.5, Sonnet 5.5
and Haiku 5.5 [R3], and a Messages API request of at most 128 MB, beyond which you get the error
413 request_too_large [R4]. When you test a real application, establish who blocks long input (the
application or the API) and what the user sees in each case.
Everyday example. An apartment building has two limits: the guard at the gate stops bulky items (the application's limit) and the lift sounds an overload alarm when the load is too heavy (the API's limit). Being stopped by the guard at the gate is very different from carrying the item all the way to the lift and then hearing the alarm. Testers need to know which layer blocks first and what the user is told at each one.
5. Technical deep dive
5.1 lab/inputs.py
| Function | Produces |
|---|---|
nfc(text), nfd(text) |
The two Unicode forms of the same text |
strip_diacritics(text) |
Vietnamese without diacritics ("hủy đơn" becomes "huy don") |
with_zero_width(text, every) |
Inserts U+200B between letters |
of_length(n, tail) |
A string of exactly n characters ending in tail (a real question after a long paste) |
boundary_lengths(limit) |
[limit - 1, limit, limit + 1] |
describe(text) |
The length, the length after NFC, and the non-printing characters or combining marks |
Worked example. The three functions you will use most, run from the lab folder (save as vd_l02b.py):
from lab import inputs
print(repr(inputs.of_length(12, " SE1001")))
print(inputs.boundary_lengths(2000))
print(ascii(inputs.strip_diacritics("Đơn hàng của tôi đâu?")))
Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions give identical output):
'aaaaa SE1001'
[1999, 2000, 2001]
'Don hang cua toi dau?'
of_length(12, " SE1001"): the tail is 7 characters long, so the function adds 5 lettersain front to reach 12.boundary_lengths(2000): the three boundary values of §4.1.strip_diacritics(...): typing without diacritics as on a phone, includingĐbecomingD.
5.2 Where to normalize?
The usual fix is to normalize once, at the entry point: unicodedata.normalize("NFC", text) and strip
invisible characters, before any comparison, regex or length count. The typical defect is normalizing in
some code branches but not all. That is why you test NFD for each flow (returns, handoff to staff, order
lookup), not just one.
Everyday example. A restaurant kitchen rules that vegetables are washed once, at the delivery door, before they go into any dish. If only the salad station washes them and the hot-pot station does not, a clean salad proves nothing about the hot pot. That is why you test NFD for each flow: v1 normalizes in the handoff flow but not in the returns flow (§8.2).
The oracles in lab/oracles.py also normalize to NFC before comparing. Otherwise the oracle itself would give a
false fail when the product answers in NFD form.
5.3 Recording a known defect with xfail(strict=True)
When the current build violates the contract, the test must still state the contract. Mark it
xfail(strict=True) with a reason: the run stays green, but the defect is recorded. If one day the defect is
fixed (on purpose or by accident), the test becomes XPASS and fails the run, forcing someone to take another
look. The lab enables xfail_strict = true in pytest.ini. You met this technique in L1-M03-L01.
Good vs bad.
| Weak | Good |
|---|---|
Change the expectation to the current behaviour (== "too_long" for 2000 characters) to make the run green |
Keep the contract's expectation and add xfail(strict=True, reason="v1 defect: 2000 chars rejected, off by one") |
Why: the first way writes a wrong contract into the test suite. When a developer fixes the defect, that test fails and blocks the correct fix.
6. The QA perspective
- What to test: one representative per equivalence class; three boundary values per limit; NFD for each flow; no diacritics, mixed language, malformed input.
- What can go wrong: off-by-one; silent truncation that loses the question; uneven normalization; a regex that does not catch malformed input; the product guessing instead of asking again.
- Where expectations come from: from the contract. If the contract says nothing, that is an issue (a question), not a bug.
- How to report: unusual input is often unreadable in a report. Record the input with
repr()orascii()so the reader sees\u0300or\u200b, and record the length.
7. Real-world scenarios
Scenario 1 (fictional): a long log. A customer pastes 3 pages of error logs and then asks "đơn SE1001 đâu
rồi?" ("where is that order now?") at the end. The application cuts the message to its first 2000 characters to
save tokens. The question is lost, and the bot gives a confident, generic answer. No error is recorded. The test
of_length(2100, " đơn SE1001 đâu rồi") would catch this defect.
Scenario 2 (fictional): copied from a Word file. A customer-service agent copies a model answer from an internal document into the test chat box. The keyword filter does not recognise it, because the pasted text is in NFD form. The lesson: test data should include text pasted from many sources, not just typed text.
8. Hands-on tutorial
8.1 Running the demo
python -m lab.demo l02
Output (copied from a real run, 2026-10-31):
empty len= 0 -> clarify Bạn cần mình hỗ trợ gì về đơn hàng?
whitespace only len= 4 -> clarify Bạn cần mình hỗ trợ gì về đơn hàng?
1999 chars len=1999 -> order_status Đơn SE1001: đang giao.
2000 chars len=2000 -> too_long Tin nhắn dài quá 2000 ký tự. Bạn rút gọn giúp mình nhé.
2001 chars len=2001 -> too_long Tin nhắn dài quá 2000 ký tự. Bạn rút gọn giúp mình nhé.
refund NFC len= 29 -> refund_policy Bạn có thể đổi trả trong 30 ngày kể từ ngày nhận hàng.
refund NFD len= 37 -> out_of_scope Mình chỉ hỗ trợ đơn hàng, đổi trả và chuyển nhân viên.
no diacritics len= 18 -> out_of_scope Mình chỉ hỗ trợ đơn hàng, đổi trả và chuyển nhân viên.
mixed vi/en len= 20 -> refund_policy Bạn có thể đổi trả trong 30 ngày kể từ ngày nhận hàng.
malformed ID len= 19 -> clarify Bạn cho mình mã đơn (dạng SE1234) nhé.
lowercase ID len= 10 -> order_status Đơn SE1002: đang xử lý.
What the eye cannot see:
NFC 'ho\xe0n ti\u1ec1n' {'length': 9, 'nfc_length': 9, 'hidden': [], 'hidden_count': 0}
NFD 'hoa\u0300n tie\u0302\u0300n' {'length': 12, 'nfc_length': 9, 'hidden': ['U+0300', 'U+0302', 'U+0300'], 'hidden_count': 3}
zero-width 'ho\u200b\xe0n' {'length': 5, 'nfc_length': 5, 'hidden': ['U+200B'], 'hidden_count': 1}
In English, the answers read: "What do you need help with regarding your order?"; the order status ("in delivery", "being processed"); "The message is longer than the limit. Could you shorten it for me?"; the returns answer; "I only help with orders, returns and handoff to staff."; and "Please give me the order number (in the form shown)."
Compare each line with the contract:
| Line | Contract | Conclusion |
|---|---|---|
2000 chars -> too_long |
C6: 1-2000 is valid | Bug (off-by-one) |
refund NFD -> out_of_scope |
C6: NFC/NFD does not change the result | Bug |
no diacritics -> out_of_scope |
The contract says nothing | Issue: ask the product owner |
mixed vi/en answers in Vietnamese |
C5 | Correct |
malformed ID -> clarify |
C2: no guessing | Correct |
In the NFD line, hidden lists the combining marks (U+0300, U+0302). They are not "hidden" the way U+200B
is, but they are what makes the two strings different.
8.2 Running the tests
python -m pytest tests/test_l02_boundaries.py -v -rx
You will see two XFAIL lines with their reasons: 2000 chars rejected, off by one and refund keywords not matched in NFD form. Note that test_handoff_request_in_nfd_form passes: v1 normalizes in the handoff flow
but not in the returns flow. That is why you have to test NFD for each flow.
8.3 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
Two strings print the same but == is False |
Different Unicode forms or an invisible character | print(ascii(s)) or inputs.describe(s) |
| One XPASS test fails the run | The defect has been fixed | Remove the xfail and record it in the report |
| The editor turns NFD into NFC when saving the file | Some editors normalize text | Create NFD in code with inputs.nfd(...); do not paste it into the file |
9. Independent exercise
9.1 Main exercise
Problem: Build a boundary pack for v1.
Requirements:
- Add at least 8 rows to
PACKinexercises/test_l02_boundary_pack.py. They must cover: the two remaining boundaries of the length limit, another form of whitespace, NFD for two different flows, an invisible character inside an order number, all capitals, emoji, a sentence entirely in English, and a malformed order number. - The expectation of each row must be taken from the contract. Mark the rows that v1 violates with
pytest.param(..., marks=pytest.mark.xfail(reason="...")). - Write 1-2 questions for the product owner about inputs that the contract does not specify.
Test data: generate it yourself with lab/inputs.py.
Deliverable: the completed pack file and the list of questions.
Acceptance criteria: the run passes (xfail counts as a pass); every xfail has a reason that points to a clause; no row has an expectation taken from observed behaviour instead of from the contract.
Hint: pytest.param takes the row's values, followed by marks=. An order number with an invisible
character: "Đơn SE\u200b1001 sao rồi?".
9.2 Extra exercise: turn C6 into code (20-30 minutes)
Problem: The example in §4.2 shows that v1 counts the length of NFD text wrongly. Instead of writing the expectation by hand for each message, you write one function that describes C6 and use it as the oracle for every input.
Requirements: in exercises/test_l02_extra_c6_model.py:
- TODO 1: write
c6_class(message)returning"clarify","too_long"or"ok". Remove invisible characters (categoryCf), bring the text to NFC, trim whitespace at both ends, and only then count. The ten samplesS01-S10must get the right class. - TODO 2: run the file again, read the table comparing v1 with your function in the failure message, and
record the samples that v1 violates in
V1_MISMATCHES. - For each sample in
V1_MISMATCHES, write a one-line bug report: the input (useascii()), the result, the clause.
Run: python -m pytest exercises/test_l02_extra_c6_model.py. Until you do the work, the tests fail with
TODO 1.
Acceptance criteria: 11 tests pass; every sample in V1_MISMATCHES has a one-line bug report that points to
C6.
Hint: str.strip() already removes the no-break space (U+00A0) but not U+200B, because U+200B
is not whitespace but a format character. Does the order of the steps matter? Try sample S04.
9.3 Real-world scenario: a clinic booking chatbot
Context (fictional): The MinhAn clinic lets patients book appointments through a chatbot. The chatbot asks for three things:
- Patient number:
BNfollowed by 6 digits, for exampleBN123456. - Appointment date: day/month/year, within the next 30 days, never on a Sunday.
- Symptom description: 1-500 characters after trimming whitespace at both ends.
Your task: write (a) an equivalence-partition table for each field, (b) boundary values for the patient number, the date and the description length, (c) at least 6 negative inputs with expectations, at least 2 of them Unicode inputs (NFD, invisible characters), (d) 2 questions for the product owner about what the specification does not say.
A good answer has:
- Each field has valid and invalid classes, with one representative per class (§4.1).
- Boundary values for the length are 499, 500, 501, and for the date: today, day 30, day 31.
- The patient number has near-miss cases: 5 or 7 digits,
bn123456, the letter O instead of the digit 0, a space in the middle. - Unicode inputs have expectations derived from the specification, not from observed behaviour.
- The questions for the product owner point exactly at what the specification leaves open (for example:
is
bn123456valid? can the appointment be today?), and are not written up as bugs.
10. Knowledge check
0/20 done · Results are kept in this browser only.
P02 · True or false
P03 · Short answer
Why is testing NFD for one flow not enough?
P04 · Short answer
The bot answers out_of_scope to "toi muon hoan tien" ("I want a refund", typed without diacritics). Is this a bug or an issue? On what basis?
P05 · Short answer
(Scenario) The application truncates long messages instead of rejecting them. Write a test case that proves the silent truncation causes harm, and state the oracle you use.
P06 · Match
P08 · Multiple choice
P09 · Spot the bug
The of_length function below is copied from lab/inputs.py but has one defect. Find it.
def of_length(n, tail="", filler="a"):
"""A message of exactly n characters that ends with `tail` (the real question, pasted after a
long log, for example)."""
if len(tail) > n:
raise ValueError("tail is longer than n")
return filler * (n - len(tail) - 1) + tailP10 · Multiple choice
P11 · True or false
P12 · Recall
Lesson: L1-M04-L01P13 · Select all that apply
P14 · Short answer
You paste an NFD string into a test file, but the NFD test of the returns flow still passes on v1, even though v1 has a normalization defect in that flow. What is the likely cause, and how do you fix it?
P15 · True or false
P17 · Multiple choice
P18 · True or false
P19 · Fill in the blank
P20 · Apply now
In code-labs/l1-m04, do the extra exercise §9.2 in exercises/test_l02_extra_c6_model.py, then run python -m pytest exercises/test_l02_extra_c6_model.py.
11. Summary
- Concepts: equivalence partitioning; boundary values; NFC/NFD and canonical equivalence; invisible characters; specified and unspecified behaviour; the limits of the application and of the API.
- Skills: generating negative and boundary inputs; reading strings with
ascii(); recording a known defect withxfail(strict=True). - Pitfalls: testing only the sample questions; testing NFD for one flow; taking expectations from observed behaviour; silently truncating input.
- You can now: build a boundary pack for a Vietnamese chatbot.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Unicode Standard Annex #15: Unicode Normalization Forms (revision 58, Unicode 18.0.0) | Unicode Consortium | https://www.unicode.org/reports/tr15/ | 2026-10-31 | NFC, NFD and canonical equivalence |
| R2 | FAQ: Language Tagging (Tags block) | Unicode Consortium | https://www.unicode.org/faq/languagetagging.html | 2026-10-31 | Tag characters are "invisible format control characters" |
| R3 | Models overview | Anthropic | https://platform.claude.com/docs/en/models/overview | 2026-10-31 | 1M-token context window (models 5.5) |
| R4 | API errors | Anthropic | https://platform.claude.com/docs/en/api/errors | 2026-10-31 | 413 request_too_large; the 128 MB limit for the Messages API |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Equivalence partitioning | Phân vùng tương đương |
| Boundary value analysis | Phân tích giá trị biên |
| Off-by-one | Lỗi lệch một |
| Normalization (NFC/NFD) | Chuẩn hóa Unicode (dạng dựng sẵn / dạng tách) |
| Zero-width character | Ký tự độ rộng bằng 0 (vô hình) |
| Code-switching | Trộn ngôn ngữ trong một câu |
| Issue (vs bug) | Câu hỏi/vấn đề cần làm rõ (khác với lỗi) |