Test strategy document in Testing Fundamentals - Build an Automation Script
import unittest import os class TestStrategyDocument(unittest.TestCase): DOCUMENT_PATH = 'test_strategy_document.txt' REQUIRED_SECTIONS = [ 'Project Name:', 'Scope of Testing:', 'Testing Objectives:', 'Testing Types:', 'Testing Tools:', 'Roles and Responsibilities:', 'Test Environment Setup:', 'Test Schedule and Milestones:' ] def setUp(self): # Simulate creating the test strategy document content = ( 'Project Name: Sample Project\n' 'Scope of Testing: All modules\n' 'Testing Objectives: Verify functionality and performance\n' 'Testing Types: Functional, Performance\n' 'Testing Tools: Selenium, JMeter\n' 'Roles and Responsibilities: Tester, Test Lead\n' 'Test Environment Setup: Windows 10, Chrome Browser\n' 'Test Schedule and Milestones: Start 01-Jan, End 31-Jan\n' ) with open(self.DOCUMENT_PATH, 'w') as f: f.write(content) def tearDown(self): if os.path.exists(self.DOCUMENT_PATH): os.remove(self.DOCUMENT_PATH) def test_document_creation_and_content(self): # Check file creation self.assertTrue(os.path.exists(self.DOCUMENT_PATH), 'Document file should be created') with open(self.DOCUMENT_PATH, 'r') as f: content = f.read() # Check each required section is present and not empty for section in self.REQUIRED_SECTIONS: self.assertIn(section, content, f'Section "{section}" should be present') # Check section has content after the title start_index = content.find(section) + len(section) # Find next newline after section title end_index = content.find('\n', start_index) section_content = content[start_index:end_index].strip() self.assertTrue(len(section_content) > 0, f'Section "{section}" should not be empty') # Verify project name matches expected self.assertIn('Project Name: Sample Project', content, 'Project name should match input') # Verify scope and objectives self.assertIn('Scope of Testing: All modules', content, 'Scope should be defined') self.assertIn('Testing Objectives: Verify functionality and performance', content, 'Objectives should be defined') # Verify roles and responsibilities section self.assertIn('Roles and Responsibilities: Tester, Test Lead', content, 'Roles section should exist') # Verify test schedule self.assertIn('Test Schedule and Milestones: Start 01-Jan, End 31-Jan', content, 'Schedule should be included') if __name__ == '__main__': unittest.main()
The setUp method creates a sample test strategy document file with all required sections filled. This simulates the manual creation process.
The tearDown method deletes the file after the test to keep the environment clean.
The test method test_document_creation_and_content first checks if the file exists, ensuring the document was created.
Then it reads the file content and verifies each required section title is present and that the section is not empty, ensuring completeness.
Specific assertions check that the project name, scope, objectives, roles, and schedule match expected values, confirming accuracy.
This approach uses clear assertions with messages to help identify issues quickly.
Now add data-driven testing with 3 different project names and scopes