Beginning Test Driven Development
page 4 of 7
by Brendan Enrick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 16787/ 188

Making the Tests Pass

I do not want to spend a lot of time talking about our implementation which makes the tests pass, because it is not the focus of the article. For now I will just include a quick solution which causes the tests to pass. Keep in mind that at each step we should only write just enough to make the tests pass. We will write more tests in a moment which help us create more functionality. If we flesh out the Deck class with code that actually works, we end up with something similar to the following code.

Listing 2: The Simple Implementation

public class Deck
{
    private readonly List<Card> _cards;
 
    public Deck(List<Card> cards)
    {
        _cards = cards;
    }
 
    public int Count 
    {
        get { return _cards.Count; }
    }
 
    public Card DrawCard()
    {
        Card drawnCard = _cards[0];
        _cards.Remove(drawnCard);
        return drawnCard;
    }
}

Notice here that there are still plenty of bugs which can occur with this code. For example if the deck is empty, I am going to get an ArgumentOutOfRangeException. We need to get some more tests in place and make them pass.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 1 and 1 and type the answer here:

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2010 ASPAlliance.com  |  Page Processed at 3/12/2010 4:46:54 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search