nearcrosoft's Blogs

I think this is a Test Fixture of a very clear, Office 2007



is the definition of tested software running everything, this need "stuff" is not data, also including software to be measured, such as instantiation ready to be measured in a way of ConnectionString, prepare the database. Generally speaking, there are three methods to prepare Test Fixture.
1. Inline style: this way is, directly in the Test method of the code written ready to Test Fixture. Use the disadvantage of this method is easy to cause the code, appear many repeated copy-pasting code. Meanwhile, if the SETUP process is more complex, also can reduce test code readability, maintainability. Another problem is that this method is easy to bring test data hard-core code hidden trouble. Since there are so many faults, this method and what life? First, may for beginners, this kind of method is the most simple; Secondly, in some only prepare simple Test Fixture occasion, this method still give to write Test who provides convenient.
2. Entrust way: is simply put Test Fixture preparation for an external method of extraction, then in time of need for calls. This way is making the test code the benefits of more readable, and this part of the SETUP code can reuse. But this kind of practice can shield the cognition to SETUP process, making the test personnel concerns fell on the real test code, rather than focus on how to SETUP.
3. Implicit way: a lot of the realization of xUnit framework provides different implicit SETUP and TEARDOWN. For example MSTEST inside TestInitialize] and [[TestCleanup] tag, provides a implicit ready to Test Fixture support. Even in each test method run before, will perform a marked [TestInitialize] tag method. Use the advantages of this method is to write a can in each Test Fixture in has realized the preparation, no Test every explicitly calls a external method, but also many: shortcomings
May make test, because these hidden compared to understand ShiDiao use is not necessary, may be omit.
Cannot use oh local variables to conserve objects, can use to test the scale-up filed or property inside
Use global variables seeking