Testing is an important part of the project, and in Visual Studio , it has been well supported in testing, such as unit testing, load testing, and so on. In the area of data testing, Visual Studio 2010 also supports a variety of tests on the database, one of the most useful features is the ability for developers in the testing phase, a lot of convenient to generate random data for the database, but also can specify the rules for generating data, it is very convenient, so that in the test process , developers can have more data samples to test the project. This article describes the use of data Generation in this method.
1 Creating a SQL Server 2008 database project
First, open Visual Studio 2010, select New Project, and in the, select Build a SQL Server 2008 database project named Sampledbapp
2 Importing Data
After the database project is established, we can then import the data objects, which will import the data objects in the existing database into our established database project. First we want to connect to the database, right-click in the database project, select "Import Data Objects and Settings" in the popup menu, such as:
This will open a Data Import wizard window, for example, will prompt the user to connect to the existing database, we just need to follow the wizard to complete the steps.
After the data import is complete, the following message appears indicating that the data was imported successfully.
3 Adding a data generation plan
At this point, we can start adding a data generation plan. In the popup menu after the right mouse button in the project, select "Data Generation Plan", such as:
Continue to select Add Data conversion plan in the pop-up window, such as:
4 Select the table to add
The tables that are already in the database are then available for the user to choose which tables to generate data from, and when the user selects a table, all the columns in the table are displayed below the screen for the user to select which columns to generate the data from.
In, for example, like the Products table, you can also set its associated table, such as the Categories table, and set its associated relationship (set in the ratio to related column), such as 1:1 one-to-one relationships. While in the lower column section, note that each column in the generator generator can even be set using regular expressions to generate data, such as very handy.
5 Generating data
Once the above steps are complete, you can randomly generate the test data in the data table at the click of the Generate button or F5, and at the time of the build, you will be asked whether to generate test data in the existing database tables or to choose a different destination for the build.
6 Verifying the generated data
Finally, after the data is generated, you can check the generated data into SQL Server, for example, Visual Studio's data generator does generate a lot of test data for us.
Official Microsoft Documentation: http://msdn.microsoft.com/en-us/library/dd193262 (v=vs.100). aspx
In the original: a brief introduction to the data Generation tool in Visual Studio 2010