Testing in the software development lifecycle in Testing Fundamentals - Build an Automation Script
import unittest class TestSDLCPhases(unittest.TestCase): def setUp(self): # Setup test environment, e.g., load requirements and test cases self.requirements = ['Login', 'Search', 'Checkout'] self.test_cases = { 'Login': ['test_login_valid', 'test_login_invalid'], 'Search': ['test_search_results'], 'Checkout': ['test_checkout_process'] } self.unit_tests_passed = True self.integration_tests_passed = True self.system_tests_passed = True self.defects_logged = [] self.acceptance_tests_passed = True def test_test_cases_exist_for_requirements(self): for req in self.requirements: self.assertIn(req, self.test_cases, f"No test cases for requirement: {req}") self.assertGreater(len(self.test_cases[req]), 0, f"No test cases listed for {req}") def test_unit_tests_pass(self): self.assertTrue(self.unit_tests_passed, "Unit tests did not pass") def test_integration_and_system_tests_pass(self): self.assertTrue(self.integration_tests_passed, "Integration tests did not pass") self.assertTrue(self.system_tests_passed, "System tests did not pass") def test_defects_logged_on_failures(self): # Simulate a failure and defect logging if not self.unit_tests_passed: self.defects_logged.append('Unit test failure defect') self.assertTrue(len(self.defects_logged) >= 0, "Defects should be logged when tests fail") def test_acceptance_tests_pass_before_deployment(self): self.assertTrue(self.acceptance_tests_passed, "Acceptance tests did not pass before deployment") def tearDown(self): # Clean up test environment pass if __name__ == '__main__': unittest.main()
This test class simulates verifying testing activities in the software development lifecycle.
setUp() prepares the test environment with sample requirements and test cases, and flags for test results.
test_test_cases_exist_for_requirements() checks that each requirement has at least one test case.
test_unit_tests_pass() asserts that unit tests passed during implementation.
test_integration_and_system_tests_pass() asserts integration and system tests passed after implementation.
test_defects_logged_on_failures() simulates defect logging if tests fail and asserts defects are logged.
test_acceptance_tests_pass_before_deployment() asserts acceptance tests passed before deployment.
Each test uses clear assertions to verify expected outcomes, following best practices for test organization and clarity.
Now add data-driven testing with 3 different sets of requirements and test cases