Source: https://everyrole.dev/blog/file-upload-test-cases

# File upload test cases: type, size, empty, name

Test cases for file upload, with seven small files to keep at hand. Wrong type, renamed type, empty, at and over the limit, an odd name, the same name twice.

Nov 22, 2026  6 min read  by the EveryRole team

The test cases for file upload are few, and you can run all of them with seven small files in a folder: a good one, a wrong type, a wrong type renamed to look right, an empty one, one exactly at the size limit, one a byte over, and one with an awkward name. Add “no file chosen” and “the same name twice” and you have the list. We ran it on our practice app. It refused everything it should, and then let us overwrite another person’s file.

![Seven test files for a field that says "PNG or JPG, up to 1 MB", each with what came out on our practice app. sample.png is accepted. notes.txt and photo.png, a text file renamed, are refused with "Only PNG or JPG files." empty.png is refused with "The file is empty." exact.png, exactly 1 MB, is accepted. big.png, 1 MB and one byte, is refused with "The file is over 1 MB." A name with an accent, a space and brackets is accepted.](https://everyrole.dev/s/blog/file-upload-test-cases/files-at-hand.webp)

The seven files, and what our practice app really answered to each.

## Test cases for file upload, one row each

Our practice app has an upload page with one field. Under it, the page says “PNG or JPG, up to 1 MB”. That sentence is the specification, so each of these file upload [test scenarios](https://everyrole.dev/blog/test-scenario-vs-test-case) tests a word in it.

| Case | The file | What must come out | What our app did |
| --- | --- | --- | --- |
| An accepted file | `sample.png`, a small real picture | “Uploaded”, and the file in the list with its size | As expected |
| No file | Press “Upload” with nothing chosen | A message, the form still there | “Choose a file first.” |
| Wrong type | `notes.txt` | Refused, with the allowed types named | “Only PNG or JPG files.” |
| Wrong type, renamed | The same text, saved as `photo.png` | Refused the same way | “Only PNG or JPG files.” |
| Empty | `empty.png`, zero bytes | Refused, and it says why | “The file is empty.” |
| At the limit | `exact.png`, exactly 1 MB | Accepted | Accepted |
| Just over | `big.png`, 1 MB and one byte | Refused, with the limit named | “The file is over 1 MB.” |
| An awkward name | `été photo (1).png` | Accepted, the name shown as it is | As expected |
| The same name twice | `sample.png`, then another `sample.png` | Your decision: refuse, rename or replace, and say so | Replaced, without a word |

After every refused row, check the list: a refused file must not be in it. A refusal message above a list that quietly gained a file is a real bug, and only the list shows it.

## Upload a wrong file type, twice

Here is the wrong-type case.

![The practice app's upload page after a text file was sent. A red message says "Only PNG or JPG files." The form is still there, with the hint "PNG or JPG, up to 1 MB", and the list under it holds only the file that was there before.](https://everyrole.dev/s/blog/file-upload-test-cases/wrong-type.webp)

A text file, refused. The form is still on the page, and the list under it didn’t change.

That is a good answer: it names what is allowed, the form is still there to try again, and the list is unchanged.

The second wrong-type file is the one that matters. `photo.png` holds the same words as `notes.txt`. Only its name changed. A check that looks at the file’s name, or at the type the browser reports, lets it through, and your app now stores a “picture” that no picture viewer can open. Our practice app reads the first bytes of the file itself and refuses it. Not every upload field does.

One thing about the file chooser. The field can list its allowed types, and then the chooser greys out the rest. That is a convenience for people. It stops nobody who drags a file onto the page or switches the chooser to “All files”. The refusal has to come from the server, the same two-guards rule as for [any form](https://everyrole.dev/blog/empty-form-test).

## Size: the limit and one byte past it

Make two files with a known size. On Linux, `truncate -s 1048576 exact.png` gives a file of exactly 1 MB (of zeros: fine for a field that checks only size). For a field that checks content, start from a real picture and pad it.

Then test both sides. Exactly at the limit must be accepted, one byte over must be refused. This is [boundary testing](https://everyrole.dev/blog/boundary-value-testing) with a file where the number would be. Our practice app drew its line in the right place. The off-by-one to look for is “up to 1 MB” on the page and “less than 1 MB” in the code.

Two more things belong to size:

- **Which megabyte.** 1 MB is 1,048,576 bytes to some code and 1,000,000 to other code. Find out which your app means and write it down.
- **A file far over the limit.** Not one byte over, but a hundred times. The right answer is the same message. The wrong ones are a timeout, a blank page, or a web server’s own bare error page appearing in place of yours, because a layer in front of your app refused first.

## The empty file

Zero bytes. It has a name and a type, and nothing else. Code that reads “the first bytes” of nothing can crash, and code that only checks “was a file sent” accepts it. The right answer says the file is empty, in those words. “Upload failed” makes the person try the same file again.

## Names: odd ones, and the same one twice

An accent, a space and brackets went through our practice app and came out as typed. Try yours with those, a very long name, and a name in another script. What to look for is the name coming back changed, or the download link breaking.

Then upload the same name twice. This is where our practice app lost. The second `sample.png` replaced the first, and nothing on the page said so. Worse, the page started with a file already on it, `customer-logo.png`, standing in for another person’s upload. We uploaded our own picture under that name. The list still showed one `customer-logo.png`. Its size had changed from 1,234 bytes to 112. Their file was gone and ours was in its place.

No error, and a green “Uploaded” message. A test that checks the message passes. Only a test that looks at the list before and after sees it, which is the same lesson as in [CRUD testing](https://everyrole.dev/blog/crud-test-cases): look where the thing lives.

## After the upload

An accepted file isn’t finished at “Uploaded”.

- **It is in the list after a reload**, with the right name and size.
- **It opens.** Download it and compare it with what you sent.
- **It can be removed**, and after a reload it is still gone.

## How EveryRole runs upload cases

EveryRole treats a form with a file field as its own kind of stop. It brings its own small test files, made by code at run time, and picks the first kind the field accepts.

Its main cases there: **An accepted file**, then the clean-up, **the upload is removed** and **gone after reload**, where the app has a remove control next to the upload. Three extra cases are off until you turn them on: **A file of the wrong type** (where the page states the types), **A file just over the size limit** (where the page states a size) and **An empty file**. What the page states (its accept attribute, or the words next to the field) decides which apply, so an upload field with no stated limit gets no size case.

The accepted file’s first result waits for your yes, and later runs compare with it. The refusals and the clean-up are checked by code. It removes what it uploaded and only that, and says so when it could not.

It doesn’t try the same name twice or a renamed wrong type today, and it would not have found the overwritten file. Those two rows are yours.

## Try it on your own app

EveryRole tests your app’s real user journeys for each kind of user, from the live site, and runs them after every deploy. Paste your app’s address to see what it finds.

[Start with your app](https://everyrole.dev/signup) [How it works](https://everyrole.dev/docs#start)

## Keep reading

Forms, uploads and downloads

### [CRUD test cases: create, edit, delete, then reload](https://everyrole.dev/blog/crud-test-cases)

CRUD testing in the browser, in nine cases. After each create, edit and delete, look where the thing lives and reload. A success message is not the outcome.

Nov 22, 2026  6 min read

Forms, uploads and downloads

### [How to test a file download or a CSV export](https://everyrole.dev/blog/test-file-download)

How to test file download in four checks. A file arrived, it is the type the button names, it isn’t empty, and it holds the rows the page showed. Open the file.

Nov 22, 2026  6 min read

Forms, uploads and downloads

### [Multi-step form testing: every step, and Back](https://everyrole.dev/blog/multi-step-form-testing)

Multi-step form testing in five cases: all steps good, the wizard’s own Back, the browser’s Back, a reload mid-way, and a step opened by its address.

Nov 22, 2026  6 min read
