自动填充数据新增测试数据_用测试数据填充员工数据库
自動填充數據新增測試數據
In this article, we will examine the process of populating the employee database with dummy data, whose schema we designed in the previous article. Filling a SQL database with dummy data can be very useful when we want to run some tests. The most convenient way is the population of SQL tables with random data with the help of visual data generation tools.
在本文中,我們將研究用虛假數據填充員工數據庫的過程,虛假數據是我們在上一篇文章中設計的。 當我們要運行一些測試時,用偽數據填充SQL數據庫可能非常有用。 最方便的方法是借助可視數據生成工具來填充具有隨機數據SQL表。
借助Data Generator for SQL Server生成數據 (Generating data with the help of Data Generator for SQL Server)
For this purposes we’ll use Data Generator for SQL Server tool which is integrated into SSMS and is also included in dbForge Studio. It should be noted that realistic test data is generated based on column names, dimensions, and data types. Apart from this, the relationships between tables are also taken into account, as the process of data generation depends on them.
為此,我們將使用SQL Server的數據生成器工具,該工具已集成到SSMS中,并且也包含在dbForge Studio中 。 應該注意的是,真實的測試數據是根據列名,維度和數據類型生成的。 除此之外,表之間的關系也要考慮在內,因為數據生成的過程取決于它們。
To open this component, right-click “New Data Generation…” on the necessary database in SSMS:
要打開此組件,請在SSMS的必要數據庫上右鍵單擊“ New Data Generation…”:
Img. 1. Running the Data Generator for SQL Server tool in SSMS圖 1.在SSMS中運行SQL Server的數據生成器工具If you are using dbForge Studio, in the main menu, choose Tools\New Data Generation…:
如果使用的是dbForge Studio,請在主菜單中選擇“工具\新數據生成...”:
Img.2. Running the Data Generator for SQL Server tool in dbForge Studio圖2。 在dbForge Studio中運行SQL Server的數據生成器工具In the resulting window, on the “Connection” tab, you can see the current MS SQL Server instance and the database selected for data generation, which can be edited (if necessary). Then click the “Next” button:
在出現的窗口中,在“連接”選項卡上,您可以看到當前的MS SQL Server實例以及為生成數據而選擇的數據庫,可以對其進行編輯(如有必要)。 然后點擊“下一步”按鈕:
Img.3. Setting the “Connection” tab圖3。 設置“連接”標簽Next, on the “Options” tab, let’s set the options of data generation for the database:
接下來,在“選項”選項卡上,讓我們設置數據庫的數據生成選項:
Img.4. Setting data generation options圖4。 設置數據生成選項Note that you can generate SQL test data in different modes:
請注意,您可以采用不同的方式生成SQL測試數據:
You can also clear data before generation by setting the “Truncate data from table before generation” parameter.
您還可以通過設置“在生成之前從表中截斷數據”參數來生成之前清除數據。
You can set the value distribution mode in one of the following ways:
您可以通過以下方式之一設置值分配模式:
Also, you can set column properties:
另外,您可以設置列屬性:
You can save the settings to a .bat file by pressing the “Save Command Line…” button located on the lower left of the data generation settings window.
您可以通過按數據生成設置窗口左下角的“保存命令行...”按鈕將設置保存到.bat文件。
After you are finished with the settings, on the lower right of the data generation settings window, press the “Open” button.
設置完成后,在數據生成設置窗口的右下角,按“打開”按鈕。
You will then see a progress bar showing the table metadata loading. After that, the window with detailed data generation settings for each selected table appears:
然后,您將看到顯示表元數據加載的進度條。 之后,將出現一個窗口,其中包含每個選定表的詳細數據生成設置:
Img.5. Detailed data generation settings for each selected table圖5。 每個選定表的詳細數據生成設置On the left, you should select the tables and columns you want to populate, and on the right, you should set the table generation mode for the selected table.
在左側,應選擇要填充的表和列,在右側,應為所選表設置表生成模式。
At the same time, below are the instances of generated data (note that they represent real names).
同時,下面是生成的數據的實例(請注意,它們代表真實姓名)。
In the top right corner, there is a button of data generation settings that were described above.
在右上角,有一個上述數據生成設置的按鈕。
To start the data generation process, click on the green arrow at the top center of the window. Then, you will see the window for selecting additional settings. Here, on the Output tab, you need to select exactly where to generate the data, in the form of a script, save it to a file or to a database. Let us select the last option and press Next:
要開始數據生成過程,請單擊窗口頂部中心的綠色箭頭。 然后,您將看到用于選擇其他設置的窗口。 在這里,您需要在“輸出”選項卡上以腳本的形式精確選擇生成數據的位置,然后將其保存到文件或數據庫中。 讓我們選擇最后一個選項,然后按Next:
Img. 6. Setting the “Output” tab圖 6.設置“輸出”選項卡Then, you can set additional parameters on the Options tab. In this case, you need to uncheck database backup options and press “Next”:
然后,您可以在“選項”選項卡上設置其他參數。 在這種情況下,您需要取消選中數據庫備份選項,然后按“下一步”:
Img.7. Setting the “Options” tab圖7。 設置“選項”標簽On the “Additional Scripts” tab, you can set additional scripts. In our case, we just press “Next”:
在“其他腳本”選項卡上,可以設置其他腳本。 在我們的情況下,我們只需按“下一步”:
Img.8. Setting the “Additional Scripts” tab圖8。 設置“其他腳本”選項卡On the “Summary” tab, we can see the information about settings and also warnings. Here, you can also save all settings as a .bat file, by pressing the bottom left “Save Command Line…” button. To run the data generation process, you need to press the “Generate” button:
在“摘要”選項卡上,我們可以看到有關設置和警告的信息。 在這里,您還可以通過按左下角的“保存命令行...”按鈕將所有設置另存為.bat文件。 要運行數據生成過程,您需要按“ Generate”按鈕:
Img.9. The general information and warnings on the Summary tab圖9。 摘要選項卡上的常規信息和警告The window of data generation process appears:
出現數據生成過程窗口:
Img.10. Data generation process圖10。 數據生成過程Then, the tables will be populated with data. For instance, the Employee table has the following generated data:
然后,將在表中填充數據。 例如,Employee表具有以下生成的數據:
Img.11. The examples of generated data in the Employee table圖11。 Employee表中生成的數據的示例結論 (Conclusions)
To sum up, we populated the database with realistic data for testing both functionality and load. It is possible to generate much more random data for load tests. In addition to that, the very process of testing can be accelerated by means of the dbForge Unit Test tool.
綜上所述,我們在數據庫中填充了用于測試功能和負載的實際數據。 可以為負載測試生成更多隨機數據。 除此之外,還可以通過dbForge單元測試工具來加速整個測試過程。
What is more, through the use of SQL data generation, you can calculate not only a database growth rate but also a query performance difference that results from the data volume increase.
而且,通過使用SQL數據生成,您不僅可以計算數據庫增長率,還可以計算由于數據量增加而導致的查詢性能差異。
Originally published at https://blog.devart.com on July 22, 2020.
最初于 2020年7月22日 發布在 https://blog.devart.com 上。
翻譯自: https://towardsdatascience.com/populating-the-employee-database-with-test-data-aa76419eebb6
自動填充數據新增測試數據
總結
以上是生活随笔為你收集整理的自动填充数据新增测试数据_用测试数据填充员工数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 海马汽车回应“有没有和小米公司深度合作造
- 下一篇: 未来人类预告新款 X711 笔记本:配备