0
0
Testing Fundamentalstesting~10 mins

Data integrity checks in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that data saved in a database remains accurate and unchanged after a save operation. It checks if the data retrieved matches the data input, ensuring data integrity.

Test Code - unittest
Testing Fundamentals
import unittest

class TestDataIntegrity(unittest.TestCase):
    def setUp(self):
        # Simulate a simple in-memory database as a dictionary
        self.database = {}

    def save_data(self, key, value):
        # Simulate saving data
        self.database[key] = value

    def get_data(self, key):
        # Simulate retrieving data
        return self.database.get(key, None)

    def test_data_integrity_after_save(self):
        input_data = {'id': 1, 'name': 'Alice', 'age': 30}
        self.save_data(input_data['id'], input_data)
        retrieved_data = self.get_data(input_data['id'])
        self.assertEqual(retrieved_data, input_data, "Data retrieved does not match data saved")

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and setUp method initializes an empty in-memory databaseEmpty dictionary simulating database: {}-PASS
2Test calls save_data with key=1 and value={'id':1, 'name':'Alice', 'age':30}Database now contains: {1: {'id':1, 'name':'Alice', 'age':30}}-PASS
3Test calls get_data with key=1 to retrieve saved dataRetrieved data is {'id':1, 'name':'Alice', 'age':30}Check if retrieved data equals input dataPASS
4Assertion compares retrieved data with input dataBoth data sets match exactlyassertEqual passes confirming data integrityPASS
5Test ends successfullyNo errors, test passed-PASS
Failure Scenario
Failing Condition: Data retrieved from the database does not match the data saved (e.g., data corruption or incorrect save)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after saving data?
AThat the data is deleted after saving
BThat the database is empty
CThat the data retrieved matches the data saved
DThat the data is saved twice
Key Result
Always verify that data retrieved after saving matches exactly what was saved to ensure data integrity and catch any corruption or unintended changes.