import unittest
class TestPlanStructureTest(unittest.TestCase):
def setUp(self):
with open('test_plan.txt', 'r', encoding='utf-8') as file:
self.content = file.read()
def test_title_section_present(self):
self.assertIn('Test Plan Title', self.content, 'Title section missing')
def test_introduction_section_present(self):
self.assertIn('Introduction', self.content, 'Introduction section missing')
intro_start = self.content.find('Introduction')
intro_end = self.content.find('\n\n', intro_start)
intro_text = self.content[intro_start:intro_end].strip()
self.assertTrue(len(intro_text) > len('Introduction'), 'Introduction section is empty')
def test_scope_section_present(self):
self.assertIn('Scope', self.content, 'Scope section missing')
def test_objectives_section_present(self):
self.assertIn('Objectives', self.content, 'Objectives section missing')
def test_criteria_section_present(self):
self.assertIn('Test Criteria', self.content, 'Test Criteria section missing')
def test_schedule_section_present(self):
self.assertIn('Schedule', self.content, 'Schedule section missing')
def test_resources_section_present(self):
self.assertIn('Resources', self.content, 'Resources section missing')
def test_environment_section_present(self):
self.assertIn('Test Environment', self.content, 'Test Environment section missing')
def test_risks_section_present(self):
self.assertIn('Risks and Contingencies', self.content, 'Risks and Contingencies section missing')
def test_approval_section_present(self):
self.assertIn('Approval', self.content, 'Approval section missing')
if __name__ == '__main__':
unittest.main()This test script reads the test plan document from a text file named test_plan.txt. It uses Python's unittest framework to check that each required section header is present in the document.
Each test method checks one section for presence and, where appropriate, verifies the section is not empty. Using separate methods helps keep tests clear and focused.
Assertions include messages to explain what is missing if a test fails. The setUp method reads the file once before tests run, improving efficiency.