项目作者: dsietz

项目描述 :
Test Data Generation
高级语言: Rust
项目地址: git://github.com/dsietz/test-data-generation.git
创建时间: 2016-08-25T16:32:24Z
项目社区:https://github.com/dsietz/test-data-generation

开源协议:Apache License 2.0

下载


Test Data Generation

License
Coverage Status
Docs.rs

Linux: Build Status
Windows: Build status

Fast test data generation!

Description

For software development teams who need realistic test data for testing their software, this Test Data Generation library is a light-weight module that implements Markov decision process machine learning to quickly and easily profile sample data, create an algorithm, and produce representative test data without the need for persistent data sources, data cleaning, or remote services. Unlike other solutions, this open source solution can be integrated into your test source code, or wrapped into a web service or stand-alone utility.

PROBLEM


In order to make test data represent production, (a.k.a. realistic) you need to perform one of the following:

  • load data from a production environment into the non-production environment, which requires ETL (e.g.: masking, obfuscation, etc.)
  • stand up a pre-loaded “profile” database that is randomly sampled, which requires preparing sample data from either another test data source
    or production environment (option #1 above)

SOLUTION


Incorporate this library in your software’s testing source code by loading an algorithm from a previously analyzed data sample and generating
test data during your tests runtime.


Table of Contents

What’s New

Here’s what’s new …

0.3.4

About

test data generation uses Markov decision process machine learning to create algorithms that enable test data generation on the fly without the overhead
of test data databases, security data provisioning (e.g.: masking, obfuscation), or standing up remote services.

The algorithm is built on the bases of:

  1. character patterns
  2. frequency of patterns
  3. character locations
  4. beginning and ending characters
  5. length of entity (string, date, number)

Usage

There are multiple ways to use the Test Data Generation library. It all depends on your intent.

Profile

The easiest way is to use a Profile. The profile module provides functionality to create a profile on a data sample (Strings).
Once a profile has been made, data can be generated by calling the pre_generate() and generate() functions, in that order.

  1. extern crate test_data_generation;
  2. use test_data_generation::profile::profile::Profile;
  3. fn main() {
  4. // analyze the dataset
  5. let mut data_profile = Profile::new();
  6. // analyze the dataset
  7. data_profile.analyze("Smith, John");
  8. data_profile.analyze("Doe, John");
  9. data_profile.analyze("Dale, Danny");
  10. data_profile.analyze("Rickets, Ronney");
  11. // confirm 4 data samples were analyzed
  12. assert_eq!(data_profile.patterns.len(), 4);
  13. // prepare the generator
  14. data_profile.pre_generate();
  15. // generate some data
  16. println!("The generated name is {:?}", data_profile.generate());
  17. // save the profile (algorithm) for later
  18. assert_eq!(data_profile.save(&String::from("./tests/samples/sample-00-profile")).unwrap(), true);
  19. // later... create a new profile from the saved archive file
  20. let mut new_profile = Profile::from_file(&String::from("./tests/samples/sample-00-profile"));
  21. new_profile.pre_generate();
  22. // generate some data
  23. println!("The generated name is {:?}", new_profile.generate());
  24. }

Data Sample Parser

If you are using CSV files of data samples, then you may wish to use a Data Sample Parser.
The data_sample_parser module provides functionality to read sample data, parse and analyze it, so that test data can be generated based on profiles.

  1. extern crate test_data_generation;
  2. use test_data_generation::data_sample_parser::DataSampleParser;
  3. fn main() {
  4. let mut dsp = DataSampleParser::new();
  5. dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv"), None).unwrap();
  6. println!("My new name is {} {}", dsp.generate_record()[0], dsp.generate_record()[1]);
  7. // My new name is Abbon Aady
  8. }

You can also save the Data Sample Parser (the algorithm) as an archive file (json) …

  1. extern crate test_data_generation;
  2. use test_data_generation::data_sample_parser::DataSampleParser;
  3. fn main() {
  4. let mut dsp = DataSampleParser::new();
  5. dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv"), None).unwrap();
  6. assert_eq!(dsp.save(&String::from("./tests/samples/sample-01-dsp")).unwrap(), true);
  7. }

and use it at a later time.

  1. extern crate test_data_generation;
  2. use test_data_generation::data_sample_parser::DataSampleParser;
  3. fn main() {
  4. let mut dsp = DataSampleParser::from_file(&String::from("./tests/samples/sample-01-dsp"));
  5. println!("Sample data is {:?}", dsp.generate_record()[0]);
  6. }

You can also generate a new csv file based on the data sample provided.

  1. extern crate test_data_generation;
  2. use test_data_generation::data_sample_parser::DataSampleParser;
  3. fn main() {
  4. let mut dsp = DataSampleParser::new();
  5. dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv"), None).unwrap();
  6. dsp.generate_csv(100, &String::from("./tests/samples/generated-01.csv"), None).unwrap();
  7. }

Examples

This library comes with the following examples. To run the examples.

  • Demo 1 : Demonstrates the basic feature of the library to generate dates and people’s names from the built-in demo data sets.

    cargo run --example 01_demo

  • Demo 2 : Demonstrates the basic feature of the library to generate dates and people’s names from a CSV file.

    cargo run --example 02_demo

  • Demo 3 : Demonstrates the ability to continuously add new analyzed data to an existing profile.

    cargo run --example 03_demo

How to Contribute

Details on how to contribute can be found in the CONTRIBUTING file.

License

test-data-generation is primarily distributed under the terms of the Apache License (Version 2.0).

See LICENSE-APACHE “Apache License for details.