Database testing and database Testing

Source: Internet
Author: User

Database testing and database Testing

To ensure the correctness of the test at the business layer, we must test the database. However, at present, I did not expect to test the database in the memory. I can only perform integration tests. Next, let's talk about the test on the data layer.

Because in the database, we cannot control that we can only pass the black box test, give the value, and then return the expected results to determine whether the result is successful. However, in the test, we must ensure singularity. This is a metaphor. When we Add a piece of data during the test, the database may generate a piece of dirty data, if you run the test once a day, the consequences are terrible. However, some people say that adding and deleting a production area are not suitable for testing. As a result, you cannot add or delete a test. What should you do if it is modified. So you need to adopt a rollback Mechanism during testing.

Use TransactionScope to roll back and modify data

Let's take an example.

First, we define a TransactionScope

private TransactionScope _scope;

Then initialize in setup

[SetUp]        public void SetUp()        {            this._scope = new TransactionScope(TransactionScopeOption.Required);        }

Then we can test the code below.

        [Test]        public void Create_CreateSuccessful_ReturnsTrue()        {            var userInfo = CreateUserInfo();            var userDal = new UserDal();            bool result = userDal.Create(userInfo);            Assert.IsTrue(result);        }

Finally, we release this thing in teardown.

[TearDown]        public void TearDown()        {            this._scope.Dispose();        }

OK, so we have completed the test on the data layer. The test result is as follows:

However, some references to soa only need to be correctly configured.

 

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.