TestDriven. NET & ndash; Quick Start

Source: Internet
Author: User

TestDriven. NET-Quick Start [translation]

Introduction

This section provides a quick start guide to use TestDriven in any version of vs. NET. NET

TDD (test-driven development) is a habit of writing unit tests before you write your code. Write unit tests before writing code, and then make the tests pass so that you can better understand your intentions and goals. TDD (test-driven development) Also encourages code coverage. It not only improves the quality of code, but also allows you to refactor some internal classes or methods, and quickly and easily test external object interfaces.

TestDriven. NET is a VS plug-in type unit test. he used his original name NUnitAddIn for many years. it supports multiple unit testing frameworks including NUnit, MbUnit and MSTS and.. NET. both the personal and commercial editions can play their best.

Install

TestDriven.. NET can be installed using admin or Restricted Users. by default, the current user is installed. because the restricted user does not access the Program Files folder, the installation will be performed in the current user's 'application Data \ TestDriven.. NET 'folder. the Administrator will install the file to 'program Files \ TestDriven.. NET 'folder. the default folder can be changed under 'custom' on the 'Choose Setup type' page.

TestDriven. NET is packaged into the NUnit and MbUnit unit testing frameworks based on different functions. It also contains an adapter for unit testing executed in VSTS. They will be in the 'testdriven. net' subfolder. (1)

Figure 1:. TestDriven. NET Setup

Run the test

After TestDriven. NET is installed, restart vs and the 'run Test (s) 'command (within the scope of the Test code, click the mouse) to quickly compile the Test cases. It will perform the test method by default. It will automatically detect the used test framework and execute the current test case. The test will be executed by the test engine as an external process. This process will continue and increase the number of tests executed later. Once a test process is captured, a Rocket icon will appear in the prompt box.

If the code editing option is selected, the test to be executed will be terminated at the cursor position. When you right-click inside any method, each separate test of 'runtest (s) will be executed (2 ). Right-click 'run Test (s) 'and all tests are executed in a namespace. The 'run Test (s) 'button is also found in 'solution Explorer'. It can be used for testing in a Solution, project, or project item.

Figure 2. Run Test (s) menu item

Random test

Random testing provides a useful alternative to discard the command line program. In any case, they cannot replace true unit tests. Of course, they will plan to provide a convenient local private method in the third version.

Any method can be executed by simply right-clicking 'run test' as a random Test. It can be a public, private, and static instance method. Any method can be executed as an ad-hoc test simply by right-clicking inside it and selecting 'run test (s )'. it can be a 'public', 'private ', 'static' or 'instance' method. for the Instance method, when you use the default class constructor, an object will be created. When a test is executed, the Dispose method is also called when the IDisposable interface is implemented.

If an immediate Test returns an eclipse, this parameter will be extended to the output panel of 'test. Complex objects indicate that their domains and attributes are displayed. Only a few objects are listed. The original object is converted to a string and displayed. When 'debug. WriteLine 'is used, the same result will also be included.

Test output&Test list

The 'test' output panel is a window where all Test results and warning information are displayed (3 ). Together with command line output and error messages, tracing and debugging information will also be sent. If all tests are executed in one project or solution, the test output box only displays ignored or failed tests.

When a test fails, the name of the test is displayed together with the exception information and the trace queue. If the code is compiled with some debugging information, the same stack trace information counts the number of lines. Double-clicking these parts will be a good way to handle this messy code.

Figure 3. Output Test Pane

Like sending messages in the output panel, the incorrect test nursery rhyme will be added to the task list. If many tests fail, this will create a useful summary view (4). In general, further tracing Stacks will be interesting in terms of interests. Double-click the task list in the test area to access the code.

Figure 4. Task list view

UseDebuggerTest

The 'test with' Menu provides a lot of alternative content that can be executed in the Test. You can select the Debugger option to perform the Test in vs debugging. By adding a power failure to the method and selecting 'test With debucket', you can enter a unit Test.

Figure 5 Test With Debugger

By default, VS will create all projects in a solution, when they are executed using a debugger. In VS2003 and 2005, there is an option "Only build startup projects and dependencies on Run". The selected option can reduce the time needed to compile a large solution. In vs2003, the options are 'Environment/Projects and Solutions '. Vs05 can be found under 'projects and Solutions/Build and run.

Test Item&Solution

Right-click the 'solution Explorer 'window and select 'run Test (s)'. All tests in the project will be executed. A Test that fails or is ignored will be sent to the 'test' output window and the task list, in a similar 'run Test (s) 'command. if all tests are performed in a project or solution, tracing, debugging, and command line output are forbidden,

Similarly, all tests in a Solution will right-click the Solution in the 'solution Explorer 'window and select 'run Test (s )'. the framework for each project test in the solution will be used to establish and test the correct test when executed. Items that do not contain any tests will be ignored.

Terminate a running test

When a Test is being executed, the 'abort test' option in the menu will appear in the 'tool' menu (6 ). when an option is selected, a running thread is terminated. When the test is terminated in this way, any purge logic will give an opportunity for execution.

Figure 6. Abort Test

Stop the test process

In some cases, it is necessary to stop some testing processes. The most common of them is that when an app domain is established, it is not loaded into a test. It can cause any program loaded into the app domain to be locked, and any subsequent compilation will fail. Right-click the rocket icon and select 'stop' in the notification box to use the testing process cyclically (7 ). A new Test process will be executed the next time you use the 'run Test (s) 'command.

Figure 7. Stopping the Test Process

Original http://www.testdriven.net/quickstart.aspx address

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.