Introduction
Running many tests one after another can take a long time, especially for big projects. Parallel test execution solves this by running multiple tests at the same time, making the process faster and more efficient.
Imagine a group of friends cleaning a house. If only one person cleans each room one after another, it takes a long time. But if everyone cleans different rooms at the same time, the whole house gets clean much faster.
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ Test 1 │ │ Test 2 │ │ Test 3 │ │ (Sequential) │ │ (Sequential) │ │ (Sequential) │ └──────┬────────┘ └──────┬────────┘ └──────┬────────┘ │ │ │ │ │ │ ▼ ▼ ▼ ┌───────────────────────────────────────────────────────────┐ │ Total time: Long │ └───────────────────────────────────────────────────────────┘ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ Test 1 │ │ Test 2 │ │ Test 3 │ │ (Parallel) │ │ (Parallel) │ │ (Parallel) │ └──────┬────────┘ └──────┬────────┘ └──────┬────────┘ │ │ │ │ │ │ ▼ ▼ ▼ ┌───────────────────────────────────────────────┐ │ Total time: Much shorter │ └───────────────────────────────────────────────┘
import unittest import time class TestExample(unittest.TestCase): def test_one(self): time.sleep(1) self.assertTrue(True) def test_two(self): time.sleep(1) self.assertTrue(True) if __name__ == '__main__': unittest.main(verbosity=2)
parallel test execution in software testing?parallel = true typically enables parallel runs in configs.parallel = true -> Option Dstart test1
start test2
wait for test1
wait for test2
print('All tests done')
What will be the output if both tests pass quickly?Pass the test and this pattern moves unknown