Testing is a very important part of the project. In Visual Studio 2010, there is good support for testing, such as unit testing, load testing and so on. In terms of data testing, visual studio 2010 also supports a variety of tests on the database. One of the easy-to-use functions is that it can easily generate a large number of random data for the database for developers in the test stage, and it can also specify the rules for generating data by itself, which is very convenient, so that during the test process, Developers can have more sufficient data samples to test the project. This paper introduces the use of data generation data generator.
1 create SQL Server 2008 database project
First, open Visual Studio 2010 and select new project. In the following figure, select to create a SQL Server 2008 database project named sampledbapp
2 import data
After the database project is established, we can import the data objects. Here, we import the data objects in the existing database into the database project we have established. First, connect to the database, right-click the database project, and select import data objects and settings in the pop-up menu, as shown in the following figure:
This will open a data import wizard window, as shown in the figure below. Users will be prompted to connect to the existing database. We just need to follow the wizard step by step.
After the data import is completed, the following prompt message will appear, indicating that the data has been successfully imported.
3 add data generation plan
At this point, we can start adding data generation plans. In the pop-up menu after right clicking in the project, select “data generation plan”, as shown below:
Continue to select add data conversion plan in the pop-up window, as shown in the following figure:
4 select the table to add
Next, the existing tables in the database will appear for the user to select which tables to generate data. When the user selects a table, all columns in the table will be displayed at the bottom of the screen for the user to select which columns to generate data.
In the above figure, for example, the products table can also set its associated table, such as the categories table, and its association relationship (set in the ratio to related column), such as 1:1 one-to-one relationship. In the lower column, note that the generator generator of each column can even use regular expressions to generate data, as shown in the figure below, which is very convenient.
5 generate data
After the above steps are completed, you can click the generate button as shown in the figure below or F5 to generate test data randomly in the data table immediately. During generation, the system will ask whether to generate test data in the existing database table or select another destination.
6 data generated by inspection
Finally, after the data is generated, you can check the generated data in SQL server. As shown in the figure below, it can be seen that the data generator of visual studio has indeed generated a large amount of test data for us.
Microsoft official documents:http://msdn.microsoft.com/en-us/library/dd193262(v=vs.100).aspx