Visual Studio Unit Test 5-database Test

Source: Internet
Author: User
Tags visual studio 2010

The unit test of the database is mainly to test whether the data in the database meets specific conditions. Visual Studio 2010 supports the following data unit test types (Visual Studio 2008 does not support database testing ):

Type

Description

Data checksum

Perform the checksum test on the data

Empty resultset

Whether the returned result set of the SQL statement is null

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 options. Inconclusive works the same in unit tests.

Not empty resultset

Opposite to empty resultset, the test result set is not empty.

Row count

Whether the test result set contains the specified number of data rows

Scalar Value

Test whether the returned scalar value is the same as the specified value.

For more official explanations and descriptions, see: http://msdn.microsoft.com/en-us/library/aa833423.aspx

The example in this article can be downloaded using the following link:
Http://download.csdn.net/source/3014236

Next we will start step by step to create a database unit test instance.

1. Create a new database test file:

 

2. If you create a database test file every time, the system will automatically prompt you to connect to a database:

 

3. After the creation is successful, as shown in. Click to create a script file.

 

4. See. Usergroup is a table in my database with only one data entry. Remove the default inconclusive and add the execution time and row count test conditions. Pay attention to the explanations in value. The test execution time cannot exceed 30 seconds. Only 0 rows can be returned from the test result set. Because our test result set has a row of data, we need to modify the rowcountcondition1 condition.

 

5. In the rowcountcondition1 attribute box, change 0 to 1 as follows:

 

6. Refresh the test List editor and you will be able to see the test and execution of the database we just created.

 

7. The execution result is as follows:

 

At this point, the operations on the unit test interface of the database are basically completed. Let's take a look at the background code.

Through the code, we can see that the test is actually divided into three steps: pretestaction, testaction, and posttestaction. The automatically generated code skips the pre-test and test completed parts (

 

This. databasetest1data. posttestaction = NULL; this. databasetest1data. pretestaction = NULL;) in actual operations, we can modify it as needed.

 

If you need to reprint, please indicate the original from the wolf's blog: http://blog.csdn.net/tjvictor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.