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
- CREATE DATABASE test;
-
- CREATE TABLE parent
-
- (
-
- id INT NOT NULL,
-
- PRIMARY KEY (id)
-
- ) ENGINE=INNODB;
-
- CREATE TABLE child
-
- (
-
- id INT, parent_id INT,
-
- childname VARCHAR(20) DEFAULT NULL,
-
- INDEX par_ind (parent_id),
-
- PRIMARY KEY (id),
-
- FOREIGN KEY (parent_id) REFERENCES parent(id)
-
- ON DELETE CASCADE
-
- ) ENGINE=INNODB;
Modify the configuration file dbmonster. properties:
- dbmonster.jdbc.driver=com.mysql.jdbc.Driver
-
- dbmonster.jdbc.url=jdbc:mysql://192.168.159.144:3306?dbmonster?charSet=iso-8859-2
-
- dbmonster.jdbc.username=root
-
- dbmonster.jdbc.password=123456
-
- dbmonster.jdbc.transaction.size=50
-
- # for Oracle and other schema enabled databases
-
- dbmonster.jdbc.schema=test
-
- # maximal number of (re)tries
-
- dbmonster.max-tries=1000
-
- # default rows number for SchemaGrabber
-
- dbmonster.rows=1000
-
- # progres monitor class
-
- 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!