Free tool

Online compiler with test cases

Write your program, add test cases (an input and the output you expect), and run them all at once. Each test comes back passed or failed, with what your program printed. Free, no sign-in, 46 languages.

By the OnlineCompiler.io team. Updated .

Test cases

Up to 8 tests. Each runs the code above with its own input.

  1. Test 1

  2. Test 2

How to check your code against test cases

  1. Pick a language in the editor and write or paste your program. It reads its input from standard input and prints its answer.
  2. Give each test the input your program reads and exactly what it should print. Add up to 8 tests.
  3. Choose how output is compared. The default ignores spaces at the ends of lines and blank lines at the end, as most judges do.
  4. Press Run tests. Each test passes, or shows its verdict and what your program printed instead.

The two sample tests pass with the starter program of almost every language in the editor. Replace them with your problem's examples. Run in the editor still runs the code once with the input in its Input tab, which is handy while you debug one case.

Practise for coding exams and placement tests

Coding rounds and lab exams usually judge a program the way this tool does: they run it on inputs you cannot see and compare what it prints with the expected output, under a time limit. Before you submit, paste the sample cases from the problem as tests, then add the cases that catch most mistakes:

  • the smallest input, such as 0, 1 or an empty list;
  • the largest input the problem allows, to catch slow solutions and integer overflow;
  • negative numbers, repeated values and already sorted input;
  • input with an extra space or a blank line at the end.

Print only the answer. A prompt such as Enter n: becomes part of your output and fails every test.

What each result means

ResultAPI verdictWhat happened
PassedacceptedThe program printed the expected output and exited cleanly.
Wrong answerwrong_answerIt ran without errors but printed something else. Compare the two outputs.
Time limit exceededtime_limit_exceededIt took longer than 2 seconds on that input. Look for an endless loop or a slow algorithm.
Runtime errorruntime_errorIt crashed or exited with a non-zero code. The error text shows where.
Compilation errorcompilation_errorThe code did not compile, so the tests could not run. The compiler output is shown under the tests.
Memory limit exceededmemory_limit_exceededIt used more than 512 MB of memory.
Output limit exceededoutput_limit_exceededIt printed more than 64 KB.

Run test cases from your own app

This page runs on the run-tests API. One request with the code and its tests returns a verdict for each test, an overall verdict and a score, and hidden tests return only their verdict. It is free up to 100,000 runs a month, where each test is one run, and a request holds up to 8 tests on Free, 20 on Starter and 40 on Pro.

Terminal
curl -X POST https://api.onlinecompiler.io/api/run-tests/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "python-3.14",
    "code": "a, b = map(int, input().split())\nprint(a + b)",
    "tests": [
      {"input": "1 2\n", "expected_output": "3\n"},
      {"input": "-5 5\n", "expected_output": "0\n"},
      {"input": "1000000000 1000000000\n", "expected_output": "2000000000\n", "hidden": true}
    ],
    "scoring": "percent"
  }'

For a whole judge or a grading script, see how to build an online judge and the autograder API. To put a test-checked editor on your own page, the widget's runTests() does what this page does.

Frequently asked questions

Is this online compiler with test cases free?

Yes. It needs no account and shows no ads. Your code runs on our servers, in a fresh sandbox for each test, in any of 46 languages.

How many test cases can I run at once?

Up to 8 per run here. Each test runs your program once with its own input, with a time limit of 2 seconds and 512 MB of memory.

Why does my test fail when the output looks the same?

Usually because of something you cannot see at a glance: a prompt such as input("Enter a number: ") is printed as part of the output, a value is printed with extra decimals, or the words are in a different order. With the default comparison, spaces at the end of lines and blank lines at the end do not matter; choose "Ignore all spacing" if your spacing differs inside lines.

Can my tests check decimals or tables?

Yes. "Numbers within 1e-6" accepts numbers that differ by a tiny rounding error, and "Rows in any order" accepts the same lines in a different order, which suits SQL and pandas output.

Can I hide test cases, as a judge does?

Not in this tool. The run-tests API takes "hidden": true on a test, and then returns only its verdict, never its input or output. It is free up to 100,000 runs a month, where each test is one run.

Is my code stored?

Each run is kept in execution history with its output, as with every run on the site. The security page says what is stored and for how long.