0
0
Testing Fundamentalstesting~10 mins

Test reporting in pipelines in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates running automated tests in a pipeline and verifies that the test report is generated and contains the correct pass/fail summary.

Test Code - unittest
Testing Fundamentals
import unittest

class SimpleTest(unittest.TestCase):
    def test_addition(self):
        self.assertEqual(2 + 3, 5)

    def test_subtraction(self):
        self.assertEqual(5 - 3, 2)

if __name__ == '__main__':
    # Run tests and generate report
    test_suite = unittest.defaultTestLoader.loadTestsFromTestCase(SimpleTest)
    test_runner = unittest.TextTestRunner(verbosity=2)
    result = test_runner.run(test_suite)
    # Simulate pipeline report output
    print(f"Tests run: {result.testsRun}, Failures: {len(result.failures)}, Errors: {len(result.errors)}")
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test runner starts and loads test cases from SimpleTest classTest suite contains two test methods: test_addition and test_subtraction-PASS
2Test runner executes test_additionRunning test_addition which checks if 2 + 3 equals 5AssertEqual(2 + 3, 5) passesPASS
3Test runner executes test_subtractionRunning test_subtraction which checks if 5 - 3 equals 2AssertEqual(5 - 3, 2) passesPASS
4Test runner completes and prints summary reportConsole shows: Tests run: 2, Failures: 0, Errors: 0Report correctly shows 2 tests run with zero failures and errorsPASS
Failure Scenario
Failing Condition: One of the assertions fails, e.g., test_subtraction expects wrong result
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test report summary show after running all tests?
ATests run: 2, Failures: 2, Errors: 0
BTests run: 1, Failures: 1, Errors: 0
CTests run: 2, Failures: 0, Errors: 0
DTests run: 0, Failures: 0, Errors: 0
Key Result
Always verify that your test reports in pipelines clearly show the number of tests run and any failures or errors. This helps quickly identify issues and maintain code quality.