Very disappointed with nunit

Source: Internet
Author: User

Many people have introduced the ten essential tools developed under. net. The unit test tool is nunit. I don't know how many people have practical project experience on it. After some time of use, I am very annoyed with a defect of it. I will introduce it in detail below:
Unit Tests for database-related projectsCodeTo test the addition, deletion, and modification functions. However, this will affect each other in various functional tests, damage the test database, and generate junk data so that each unit test runs in an unknown state, in short, it is a very bad thing.
In this case, the general solution is to prepare a database for testing and restore the database after each unit test is completed. This can only be called a solution, but it is not beautiful.
I found another clean solution by checking the information: "using COM +'s automatic transaction !"
The basic solution is as follows:
1. Write a class inherited from servicedcomponent, declare transactionoption. required, and roll back the transaction in the teardown method. The specific code is as follows:

Using System;
Using Nunit. Framework;
Using System. incluiseservices;
Namespace Transactiontesting
{
[Testfixture]
[Transaction (transactionoption. Required)]
Public   Class Databasefixture: servicedcomponent
{
[Teardown]
Public   Void Transactionteardown ()
{< br> If (contextutil. isintransaction)
{< br> contextutil. setabort ();
}
}
}
}

2. modify the original unit test code so that all tests are inherited from the class just written.

After reading this method, I am very excited. It's really nice! However, after careful tests, we found that nunit has very poor support for this method and many exceptions will be thrown during runtime. Is there a natural defect in calling COM + through reflection? (I didn't see the nunit code. I guess it)

 

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.