0
0
Testing Fundamentalstesting~15 mins

Test strategy document in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify the creation and content of a test strategy document
Preconditions (2)
Step 1: Open the test strategy document template
Step 2: Fill in the project name and version
Step 3: Define the scope of testing clearly
Step 4: List the testing objectives
Step 5: Specify the testing types to be performed (e.g., functional, performance)
Step 6: Identify the testing tools to be used
Step 7: Define roles and responsibilities for the testing team
Step 8: Describe the test environment setup
Step 9: Outline the test schedule and milestones
Step 10: Review the document for completeness and accuracy
Step 11: Save the document with the correct naming convention
✅ Expected Result: The test strategy document is created with all required sections filled accurately and saved properly.
Automation Requirements - Python unittest
Assertions Needed:
Verify the document file is created
Verify each required section is present and not empty
Verify the project name matches the input
Verify the scope and objectives are defined
Verify roles and responsibilities section exists
Verify the test schedule is included
Best Practices:
Use setup and teardown methods to prepare and clean test environment
Use clear and descriptive assertion messages
Validate document content by reading the file
Keep test methods focused on one verification
Use constants for expected section titles
Automated Solution
Testing Fundamentals
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.

Common Mistakes - 4 Pitfalls
Not checking if the document file was actually created before reading it
Hardcoding file paths without cleanup
Checking only for section titles but not verifying if the sections have content
Using vague assertion messages
Bonus Challenge

Now add data-driven testing with 3 different project names and scopes

Show Hint