0
0
Testing Fundamentalstesting~6 mins

Data integrity checks in Testing Fundamentals - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine sending a message or saving important information, but it gets changed or corrupted without you knowing. Data integrity checks help catch these mistakes to keep information accurate and trustworthy.
Explanation
Purpose of Data Integrity Checks
Data integrity checks are used to verify that data remains accurate and unchanged during storage, transmission, or processing. They help detect errors or tampering that could cause incorrect results or system failures.
Data integrity checks ensure data stays correct and reliable throughout its lifecycle.
Common Methods of Checking Integrity
Some common methods include checksums, hashes, and parity bits. These methods create a small summary or code from the data that can be compared later to detect changes or errors.
Checksums and hashes create a unique code to spot any changes in data.
When Integrity Checks Are Used
Integrity checks happen during data transfer over networks, when saving files to disks, or in databases to prevent corruption. They are also used in software testing to confirm data correctness after operations.
Integrity checks are applied whenever data moves or is stored to catch errors early.
What Happens When a Check Fails
If the integrity check shows a mismatch, it means the data was altered or corrupted. Systems can then reject the data, request it again, or alert users to prevent using wrong information.
Failed checks trigger actions to avoid using corrupted or wrong data.
Real World Analogy

Think of sending a sealed letter with a wax stamp. The stamp shows if the letter was opened or changed during delivery. If the stamp is broken, you know the letter might not be safe.

Purpose of Data Integrity Checks → The wax stamp that proves the letter is untouched
Common Methods of Checking Integrity → The unique shape and pattern of the wax stamp
When Integrity Checks Are Used → Checking the stamp when the letter arrives or is stored
What Happens When a Check Fails → Not trusting the letter if the wax stamp is broken
Diagram
Diagram
┌─────────────────────────────┐
│       Original Data          │
└─────────────┬───────────────┘
              │
              ▼
┌─────────────────────────────┐
│   Generate Integrity Code    │
│  (checksum, hash, parity)    │
└─────────────┬───────────────┘
              │
              ▼
┌─────────────────────────────┐
│  Store or Transmit Data +    │
│     Integrity Code           │
└─────────────┬───────────────┘
              │
              ▼
┌─────────────────────────────┐
│   Receive or Retrieve Data   │
└─────────────┬───────────────┘
              │
              ▼
┌─────────────────────────────┐
│  Recalculate Integrity Code  │
└─────────────┬───────────────┘
              │
              ▼
┌──────────────┬──────────────┐
│              │              │
│  Codes Match │  Codes Differ│
│   (Pass)     │    (Fail)    │
│              │              │
└──────┬───────┴──────┬───────┘
       │              │
       ▼              ▼
  Use Data       Reject or Request
                 Data Again
This diagram shows the flow of creating, storing, and verifying data integrity codes to detect errors.
Key Facts
Data IntegrityThe accuracy and consistency of data over its lifecycle.
ChecksumA simple code calculated from data to detect errors.
Hash FunctionA method that converts data into a fixed-size string unique to the data.
Integrity Check FailureOccurs when the calculated code does not match the original, indicating data corruption.
Parity BitAn extra bit added to data to help detect errors in transmission.
Code Example
Testing Fundamentals
import hashlib

def calculate_hash(data: str) -> str:
    return hashlib.sha256(data.encode()).hexdigest()

original_data = "Hello, world!"
hash_original = calculate_hash(original_data)

# Simulate data transmission
received_data = "Hello, world!"
hash_received = calculate_hash(received_data)

if hash_original == hash_received:
    print("Data integrity verified: no changes detected.")
else:
    print("Data integrity check failed: data was altered.")
OutputSuccess
Common Confusions
Believing data integrity checks can fix corrupted data automatically.
Believing data integrity checks can fix corrupted data automatically. Integrity checks only detect errors; they do not correct data unless combined with error-correcting methods.
Thinking all integrity checks are equally strong.
Thinking all integrity checks are equally strong. Different methods vary in strength; for example, hashes are more reliable than simple checksums.
Summary
Data integrity checks help ensure information stays accurate and unchanged during storage or transfer.
Common methods like checksums and hashes create codes that detect errors or tampering.
When a check fails, systems can reject corrupted data to prevent mistakes.