eXtreme .NET: Introducing eXtreme Programming Techniques to .NET Developers [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

eXtreme .NET: Introducing eXtreme Programming Techniques to .NET Developers [Electronic resources] - نسخه متنی

Neil Roodyn

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید












How Do You Feel About TDD?


For the next exercise, we are going to build the same program twice. First, we are going to build the program without doing any tests, and then we are going to build the same program writing the tests first. We will then see how we feel about each program.

We are going to write some code to calculate some derived data from stock price data that is passed to our code. We are going to write a class library to encapsulate the calculations for other developers to use.

The library has to take a collection of prices and timestamps for a stock price and return the high and low prices for a given date. The collection is in the form of a HashTable containing DateTime objects mapping to double values to represent timestamps mapping to prices.


Exercise 4-10: Without Tests


I provide the skeleton for you, and then you can finish the exercise. This exercise should not take more than 30 minutes to complete.


1.

Start by creating a new C# project using the class library template called NoTests.

2.

Change the name of the class that is created for you from Class1.cs to CalcClass.cs.

3.

In the CalcClass.cs file, change the code to read as follows.


using System;
using System.Collections.Specialized;
namespace NoTests
{
public class CalcClass
{
public void CalcHighLow(Hashtable DatePriceList,
DateTime day, ref decimal high, ref decimal low)
{
}
}
}

4.

Now write the code to calculate the high and low values, but do not write any tests! Good luck.



Exercise 4-11: With Tests


We are now going to do the same project again, this time by writing tests first. I will get you started, and then you can finish the exercise yourself. This exercise should not take you more than 30 minutes to complete.


1.

Create a new C# project using the class library template called WithTests.

2.

Rename the generated class file from Class1.cs to CalcClass.cs.

3.

Change the code in the CalcClass.cs file to read as follows.


using System;
namespace CsWithTests
{
public class CalcClass
{
}
}

4.

Add a reference to the Nunit.Framework.dll file.

5.

Add a new class called CalcTests.

6.

In the CalcTests class, enter the following code.


using System;
using System.Collections;
using NUnit.Framework;
namespace CsWithTests
{
[TestFixture]
public class CalcTests
{
[Test]
public void TestCalcHighLow()
{
Hashtable datePriceList;
DateTime day;
Decimal high;
Decimal low;
CalcClass calc;
//calc.CalcHighLow(datePriceList, day, high, low);
}
}
}

7.

Now you can fill in the test code yourself and then build the CalcHighLow function in the CalcClass function to make sure the tests pass. Good luck!



Confidence Test


How do you feel after completing the last two exercises? Which class library are you more confident is correct?

If you have built meaningful tests, you should feel very confident with the second library. Even if you do not believe you have put much effort into the tests in the second exercise, the very fact that you have some means of validating your code should give you some extra level of certainty.

Visual Studio.NET 2005 Team System

The next version of Visual Studio.NET will be available in several flavors. A group of these flavors is called Visual Studio.NET 2005 Team System. This group is aimed at the enterprise development community. Two of the products in this group will include an integrated unit-testing framework. This framework will be similar to NUnit. The two products that include the unit testing will be Visual Studio Team Developer and Visual Studio Team Tester. The beta of Visual Studio 2005 Team System indicates that the attributes you have learned in NUnit will differ slightly:

    TestFixture is called TestClass.

    Test is called TestMethod.

    SetUp is called TestInitialize.

    TearDown is called TestCleanup.

The lessons you have learned in this chapter will all still hold true. It will be easy to move from NUnit to the unit-testing system in Visual Studio.NET Team System.

The current plans indicate that the unit-testing tools will not be shipped with other versions of Visual Studio.NET 2005. Testing is a cornerstone of the XP practices. Testing is important to all the practices in this book. Is Microsoft making a mistake by not shipping unit-testing tools with all the versions of Visual Studio?


    / 117