ASP. net mvc Web Application Project

Source: Internet
Author: User

This article will focus on how to build a specific type of unit test in a test-driven development environment when building an ASP. net mvc Web application project.

In fact, not all unit tests are excellent TDD tests. To apply unit tests in test-driven development, you must be able to execute unit tests very quickly. However, not all unit tests can meet this requirement.

For example, Visual Studio provides a specific type of unit test support for ASP. NET websites. You must perform unit tests of this type in the context of IIS or the development web server. However, when you conduct test-driven development, this is not a proper type of unit test, because the unit test speed of this type is too slow.

In this article, I want to show you the detailed process of building a unit test for test-driven development. I will describe in detail about how to use the Visual Studio 2008 unit test framework. In addition, I will discuss several advanced topics, such as testing private methods and how to execute tests from the command line.

Quickly create an ASP. net mvc Web application project example

First, let's create a new ASP. net mvc Web application project and create a corresponding test project. This step is very easy. When you create a new ASP. net mvc Web application project, the system will prompt you whether to create a New Visual Studio test project, as shown in 1. As long as you keep the single button at the top of Figure 1, that is, the default option), you will see a new test project automatically added to your solution.

Now the question is: Since you have a test project, how do you use this test project?

When you create a new ASP. net mvc application, the project includes a controller named HomeController. This controller has two default methods named Index () and About () respectively. The HomeController project provides a test project named HomeControlleterTest. This test file contains two test methods: Index () and About ().

By default, the content of the Index () and About () test methods is empty (2 ). Next, you can add your test logic in these methods.

Suppose we want to build an online storage system. For example, you want to create a Details page to display the Details of a specific product. Then, you need to pass a query string containing ProductId to this Details page, retrieve product Details from the database, and display the information to the page.

In good test-driven development practices, you need to write a test before coding. Instead of writing any application code, you must first compile the test corresponding to the code. To create a successful Details page, the following test requirements must be met:

1) if a ProductId is not passed to this page, an exception should be thrown.
2) The ProductId should be used to retrieve a product from the database
3) if a matched product cannot be retrieved from the database, an exception should be thrown.
4) The Details view should be generated smoothly
5) The Product data should be assigned to the ViewData structure of the Details View.

The above introduces ASP. net mvc Web Application Project

  1. Analysis on PageBase and MasterPage of ASP. NET
  2. XML Web Service Method of ASP. NET
  3. Detailed description of ASP. NET environment deployment
  4. Implement ASP. NET globalization
  5. Solve the Problem of ASP. net ajax script errors

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.