Source: Visual Studio Test Five---database testing
Unit Testing of a database is primarily a test of whether data in a database meets specific criteria, andVisual Studio supports unit test types for the following data (Visual Studio does not support database testing ) :
Type |
Description |
Data Checksum |
the data is Checksum Inspection |
Empty ResultSet |
of the test execution SQL Statement returns whether the result set is empty |
Execution time |
Test Execution time |
Expected Schema |
Whether the columns and data types in the test result set match the specified test conditions |
Inconclusive |
default option. Unit tests have the same inconclusive effect . |
Not Empty ResultSet |
with the Empty ResultSet instead, test whether the result set is not empty |
Row Count |
Tests whether the result set contains the specified number of rows of data |
Scalar Value |
Tests whether the returned scalar value is the same as the specified value. |
For more official explanations and instructions, see:http://msdn.microsoft.com/en-us/library/aa833423.aspx
Examples of this article can be downloaded using the following link:
http://download.csdn.net/source/3014236
here we go . Stepby Step to build a database unit test instance.
1. Create a new database test file:
2. If you are creating a database test file every time, you will automatically be prompted to connect to a database:
3. after a successful creation, such as. Click to create a script file.
4. as shown in. usergroup is a table in my database and there is only one piece of data in it. Remove the system default inconclusive , plus the ExecutionTime and RowCount two test conditions. Notice the explanation in Value. The test execution time cannot be more than a few seconds, and the test returns only 0 rows from the result set . Because our test result set has a row of data, we want to modify the rowCountCondition1 condition.
5. in the RowCountCondition1 property box, change 0 to 1. as follows:
6. in the testlist Editor , a refresh, you can see our newly built database testing, execution.
7. The results of the implementation are as follows:
At this point, the unit test interface operation of the database is basically completed. Let's look at the background code.
through the code we can see that the test is actually divided into three steps: a predictive trial (pretestaction) , Test (testaction) , Test complete (posttestaction) three parts. Automatically generated code that omits both the pre-test and the finished part of the test (
This . Databasetest1data.posttestaction = null;this. Databasetest1data.pretestaction = null; In the actual operation, we can make changes according to our own needs.
If you want to reprint, please specify this article original from the Gray Wolf blog: http://blog.csdn.net/tjvictor
The five----database test for Visual Studio unit Testing