Back to Coding

How Do You Test a Script Before You Trust It?

How Do You Test a Script Before You Trust It?
AI Tutorials Team 26 May 2026

Testing is presented as a formal discipline with frameworks and terminology, which puts beginners off something that starts as a very simple idea: try to break it yourself before it breaks on data you care about.

What is the minimum?

Run it on a small set where you know the right answer, and check the result by hand. That single step establishes more than any amount of reading the code, and most people skip it because the output looked plausible.

What cases should you try?

  • The normal case. Ordinary data, expected result.
  • Nothing. An empty folder, an empty file, no input.
  • One item. Which frequently behaves differently from many.
  • Something wrong. A corrupt file, a missing column, text where a number should be.
  • Something awkward. Names with spaces, accents, very long values.
  • Twice. Running it again on output it has already produced.

Why does running it twice matter?

Because scripts that modify things frequently behave differently the second time. A script that appends a suffix to file names will append it again; one that moves files will find the folder empty. Both are common and neither produces an error.

How do you build sample data?

By copying a handful of real items into a test folder, including the awkward one you know exists. Four files is enough, and one of them should be the file that always causes problems.

Asking for sample data to be generated works too, and it tends to produce clean examples that miss exactly the messiness real data has.

What should you ask for?

Do not change the code. List the inputs that would make this fail, and separately the inputs that would make it produce a wrong answer without failing. For each, tell me what I would see. Then give me a short list of test cases I should actually run.

What is the difference between failing and being wrong?

The one that matters. A failure is announced; a wrong answer is not, and the second category is where the damage is. Asking for both separately produces a much more useful list than asking what could go wrong.

When should you write automated tests?

When you check the same thing by hand for the third time. At that point writing the check as code costs about the same as doing it manually once more, and it can be repeated forever.

For a script you run once, manual checking is entirely appropriate.

What about scripts you run regularly?

Worth having them check themselves. A line confirming the expected number of files were processed, and a message if not, turns a silent wrong result into a visible one, which is most of what testing achieves.

What is the mindset?

Try to break it on purpose. Somebody who has genuinely attempted to make their script fail and could not has a reasonable basis for confidence; somebody who ran it once successfully has a hope, and hopes are what produce the discovery three weeks later.