Take MySQL as an example to introduce the use of the database test tool dbmonster.

Source: Internet
Author: User

Database testing toolsDbmonsterThis document usesMySQLThe database is used as an example to test the generation of INT-type primary keys, foreign keys, and varchar-type data. Next we will introduce this process.

Preparations:

Prepare to use MySQL for testing, if you have not installed mysql please first install, then download the mysql jdbc driver, unzip and copy the mysql-connector-java-5.1.17-bin.jar file to the dbmonster-core-1.0.3 \ lib directory.

Create Database test, create table parent, child

 
 
  1. CREATE DATABASE test;  
  2.  
  3. CREATE TABLE parent   
  4.  
  5. (  
  6.  
  7. id INT NOT NULL,  
  8.  
  9.         PRIMARY KEY (id)  
  10.  
  11. ) ENGINE=INNODB;  
  12.  
  13. CREATE TABLE child   
  14.  
  15. (  
  16.  
  17. id INT, parent_id INT,  
  18.  
  19. childname VARCHAR(20) DEFAULT NULL,  
  20.  
  21.         INDEX par_ind (parent_id),  
  22.  
  23.         PRIMARY KEY (id),  
  24.  
  25.         FOREIGN KEY (parent_id) REFERENCES parent(id)  
  26.  
  27.         ON DELETE CASCADE  
  28.  
  29. ) ENGINE=INNODB; 

Modify the configuration file dbmonster. properties:

 
 
  1. dbmonster.jdbc.driver=com.mysql.jdbc.Driver  
  2.  
  3. dbmonster.jdbc.url=jdbc:mysql://192.168.159.144:3306?dbmonster?charSet=iso-8859-2  
  4.  
  5. dbmonster.jdbc.username=root 
  6.  
  7. dbmonster.jdbc.password=123456 
  8.  
  9. dbmonster.jdbc.transaction.size=50 
  10.  
  11. # for Oracle and other schema enabled databases  
  12.  
  13. dbmonster.jdbc.schema=test 
  14.  
  15. # maximal number of (re)tries  
  16.  
  17. dbmonster.max-tries=1000 
  18.  
  19. # default rows number for SchemaGrabber  
  20.  
  21. dbmonster.rows=1000 
  22.  
  23. # progres monitor class  
  24.  
  25. dbmonster.progress.monitor=pl.kernelpanic.dbmonster.ProgressMonitorAdapter 

DBMonster schema file

The schema file describes the rules for generating data. In DBMonster, data is generated by Generator. In DBMonster, the default data Generator includes two Key generators for generating non-repeated data, maxKeyGenerator and StringKeyGenerator) and 10 Data Generator respectively. The following describes how to use Data Generator.

BinaryGenerator is used to obtain binary data from external files and insert corresponding fields. This Generator has two attributes: file and nulls. The file attribute describes the data source, the nulls attribute gives the probability that the field will generate null.

BooleanGenerator is used to generate bool-type data. The Generator includes two attributes: probability and nulls. The probability attribute describes the probability of generating true data. The nulls attribute gives the probability of generating null.

ConstantGenerator is used to generate data with a fixed value. This Generator has only one attribute, constant, and returns the value to be inserted into the database;

DateTimeGenerator is used to generate DateTime-type data. The Generator includes four attributes: startDate, endDate, returnedType, nulls, startDate, and endDate, the format is yyyy-mm-dd hh24: MM: ss. returnedType describes the type of the generated data, which can be date, time, or timestamp;

DirectoryGenerator is used to insert data to the database based on the entries in the local file dictionary. This Generator has two attributes: dictFile and unique. dictFile indicates the location of the dictionary file, unique indicates whether the generated data is unique or random;

ForeignKeyGenerator is used to generate data for fields with foreign keys. This Generator contains two attributes: tableName and columnName. tableName indicates the name of the table referenced by the foreign key, columnName indicates the field name referenced by the foreign key;

NullGenerator is used to generate null data. This Generator generates null data without any parameters );

NumberGenerator users generate data of the numerical type. The Generator includes five attributes: minValue, maxValue, returnedType, scale, and nulls. MinValue and maxValue respectively provide the lower and upper boundary of the generated value. returnedType indicates the data generation type, which can be short, integer, long, float, double, or numeric; scale indicates the number of decimal places; nulls indicates the probability of null;

StringGenerator is used to generate data of the string type. The Generator includes five attributes: minLength, maxLength, allowSpaces, excludeChars, and nulls. Among them, minLength and maxLength limit the string length; allowSpaces control whether the string contains a blank space; excludeChars exclude characters not used when the string is generated; nulls indicates the probability of null;

Modify the dbmonster. properties file:

Note:

In ForeignKeyGenerator, tableName indicates the table name and field name of the master table.

Now we can use dbmonster to create random data. Command: dbmonster. bat-c dbmonster. proprities-s dbmonster-schema.xml

Executed successfully:

Child table data:

The usage of the database testing tool dbmonster is introduced here. I hope this introduction will be helpful to you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.