Blog | G5 Cyber Security

Testing with Good Data

TL;DR

If you have a lot of known good inputs for your system, use them to create a baseline test suite. This helps catch unexpected changes and regressions when you make updates.

1. Why Use Good Data for Testing?

Testing with only bad data (like trying to break things) is important, but it doesn’t tell you if your system still works normally. Good data confirms that the core functionality hasn’t been accidentally broken by changes.

2. Gathering Your Benign Inputs

You need a collection of inputs that you know will work correctly with your system. Where do these come from?

3. Creating Your Baseline Test Suite

Now you’ll turn those inputs into a repeatable test suite.

  1. Choose a Testing Framework: Select a framework appropriate for your language and system (e.g., pytest for Python, JUnit for Java).
  2. Write Test Cases: For each good input, write a test case that:
    • Loads the input data.
    • Runs it through your system.
    • Verifies the expected output.
  3. Automate Execution: Configure your framework to run all tests automatically (e.g., as part of a build process).

4. Example Test Case (Python with pytest)

Let’s say you have a function process_data(input_file) that reads data from a file and returns a result.

import pytest

def process_data(input_file):
  # Your actual processing logic here
  with open(input_file, 'r') as f:
    data = f.read()
  return data.upper() # Example: convert to uppercase

def test_good_input():
  # Create a sample input file
  with open('test_input.txt', 'w') as f:
    f.write('hello world')

  expected_output = 'HELLO WORLD'
  actual_output = process_data('test_input.txt')
  assert actual_output == expected_output

5. Running and Interpreting Results

Run your test suite regularly.

6. Maintaining Your Test Suite

Good data tests aren’t ‘set it and forget it’.

Exit mobile version