0
0
Postmantesting~10 mins

Collections and folders in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that a Postman collection contains a specific folder and that the folder has the expected number of requests. It ensures the collection structure is correct for organized API testing.

Test Code - unittest
Postman
import unittest
from postman_collection import Collection

class TestPostmanCollection(unittest.TestCase):
    def setUp(self):
        # Load collection JSON file
        with open('sample_collection.json', 'r', encoding='utf-8') as f:
            self.collection = Collection.from_json(f.read())

    def test_folder_exists_and_request_count(self):
        # Check if folder named 'User APIs' exists
        folder = next((f for f in self.collection.folders if f.name == 'User APIs'), None)
        self.assertIsNotNone(folder, 'Folder "User APIs" should exist in collection')

        # Check folder has exactly 3 requests
        self.assertEqual(len(folder.requests), 3, 'Folder "User APIs" should contain 3 requests')

if __name__ == '__main__':
    unittest.main()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsPython unittest framework initialized-PASS
2Loads 'sample_collection.json' fileCollection JSON content loaded into memory-PASS
3Parses collection JSON into Collection objectCollection object created with folders and requests-PASS
4Searches for folder named 'User APIs'Folder list scannedFolder 'User APIs' is found (not None)PASS
5Counts requests inside 'User APIs' folderFolder contains requestsFolder has exactly 3 requestsPASS
6Test endsAll assertions passed-PASS
Failure Scenario
Failing Condition: Folder named 'User APIs' does not exist or has a different number of requests
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check first in the Postman collection?
AIf the collection file is empty
BIf the collection has any requests
CIf the folder named 'User APIs' exists
DIf the folder has more than 5 requests
Key Result
Always verify the structure of your Postman collections by checking folders and request counts to keep your API tests organized and reliable.