Guides

CSV IMPORT TESTING

CSV test data for import validation

Build small, repeatable CSV fixtures that expose mapping errors, broken quoting, unsafe spreadsheet values, invalid rows, and locale assumptions before a customer file reaches production.

QUICK ANSWER

How should you test a CSV import?

Begin with one small valid file that matches the documented column names, order, encoding, and required fields. Then create separate fixtures for quoted commas, embedded quotes, Unicode, blank values, duplicate IDs, invalid types, missing columns, extra columns, and spreadsheet-formula prefixes. Verify both the accepted rows and the exact row-level errors. Keep each file repeatable so a failed import can be reproduced.

Generate repeatable CSV test data →

STEP 1

Start with the smallest valid baseline file

Your first fixture should prove that the happy path works. Use only the columns the importer requires and three to five fictional records. A small file makes field mapping and error messages easier to inspect than a thousand-row export.

id,fullName,email,country,active
MDK-408-0001,Nora Shah,nora.shah@example.com,United States,true
MDK-408-0002,Caleb Ramirez,caleb.ramirez@example.com,United States,false
Keep the baseline valid. Add one failure class at a time in later fixtures. A single file containing every possible defect makes it hard to tell which validation rule actually failed.

STEP 2

Test delimiters, quotes, and line breaks

CSV is not simply text joined with commas. A field containing a comma, quote, or line break must be quoted; a quote inside a quoted field is represented by two quotes. Your importer should parse these values as one field rather than shifting the remaining columns.

id,fullName,address,note
MDK-408-0003,"Maya O""Connor","18 Cedar Lane, Austin","Line one
Line two"
Expected acceptance
  • Quoted commas remain inside one value
  • Doubled quotes become one literal quote
  • A quoted line break stays in the same row
Expected rejection
  • Unclosed quoted fields
  • Unexpected column counts
  • Malformed escape sequences

STEP 3

Use Unicode and locale-shaped values deliberately

Include names and addresses with accented Latin characters and non-ASCII scripts when your product claims to support them. Confirm that the file is decoded as UTF-8, stored without replacement characters, and displayed without truncation. Locale-shaped data should stay internally consistent: a country, region, postal code, and phone number should belong to the same locale.

Useful Unicode fixtureZoë · José · Łukasz · 李明 · مرحبا

Use fictional combinations and document the encoding expected by the importer.

STEP 4

Test column and row-level schema errors separately

An importer should explain whether the file itself is invalid or whether a particular record failed validation. Create focused fixtures for missing required headers, unknown headers, blank required values, invalid booleans or dates, duplicate IDs, and values longer than the destination field allows.

Header failuresMissing, duplicated, renamed, reordered, or unexpected columns
Type failuresText in numeric fields, impossible dates, or unsupported boolean forms
Record failuresDuplicate IDs, missing required values, and values beyond limits
Batch failuresEmpty files, excessive row counts, interrupted uploads, and partial imports

STEP 5

Test spreadsheet-formula safety

Spreadsheet applications may interpret cells beginning with =, +, -, or @ as formulas. If users can download rejected rows or reopen an export in a spreadsheet, neutralize untrusted formula-like values before export and verify that they remain text.

id,displayName,note
MDK-408-0004,Formula test,"'=2+2"
MDK-408-0005,At-sign test,"'@example"

Prefixing with an apostrophe is one common spreadsheet-oriented defense, but the correct handling depends on the product and its consumers. Treat the original value as untrusted input and test the complete import-to-export path.

STEP 6

Assert outcomes, not only upload success

A green upload message is not enough. Verify the number of accepted and rejected rows, the stored field values, duplicate handling, rollback behavior, and the row numbers reported in validation errors. If partial imports are allowed, confirm that rejected rows do not silently create incomplete records.

Assert after import
  • Accepted and rejected row counts
  • Exact stored values and types
  • Actionable row and column errors
  • Duplicate and rollback behavior
Record with the test
  • Fixture filename and purpose
  • Expected encoding and delimiter
  • Generator seed and settings
  • Expected result for every invalid row

MINIMUM TEST MATRIX

CSV import cases worth keeping

  • A small valid UTF-8 baseline file.
  • A quoted comma, embedded quote, and quoted line break.
  • Unicode names and locale-consistent addresses.
  • Missing, extra, duplicated, and reordered headers.
  • Blank required fields and invalid data types.
  • Duplicate identifiers and row-count boundaries.
  • Formula-like values that must remain plain text.
  • A repeatable medium-size batch for performance checks.

COMMON QUESTIONS

CSV import validation FAQ

What should a CSV import test include?

Include a valid baseline file, quoted values containing commas or line breaks, Unicode text, optional blanks, duplicate identifiers, invalid types, extra and missing columns, and a deliberately unsafe spreadsheet-formula value. Test each failure class separately so the result is easy to diagnose.

Should CSV test data use real customer records?

No. Use fictional records and reserved example domains. Production exports can expose personal data and may contain cases that are difficult to share safely with a development or QA team.

How do I make generated CSV test data repeatable?

Save the field selection, locale, row count, and numeric seed with the test. Reusing the same configuration should recreate the same underlying records, which makes import failures easier to reproduce.

BUILD THE FIXTURE

Generate the baseline, then add focused failures

Use the bulk generator to choose fields, locale, row count, and a repeatable seed. Export CSV for the valid baseline, then maintain separate hand-edited fixtures for each invalid case your importer must reject.