Skip to Main Content
Professional Visual Studio® 2008
book

Professional Visual Studio® 2008

by Nick Randolph, David Gardner
July 2008
Intermediate to advanced content levelIntermediate to advanced
1026 pages
27h 59m
English
Wrox
Content preview from Professional Visual Studio® 2008

20.1. Your First Test Case

Writing test cases is not a task that is easily automated, as the test cases have to mirror the functionality of the software being developed. However, at several steps in the process code stubs can be generated by a tool. To illustrate this, start with a fairly straightforward snippet of code to learn to write test cases that fully exercise the code. Setting the scene is a Subscription class with a private property called CurrentStatus, which returns the status of the current subscription as an enumeration value:

Public Class Subscription
    Public Enum Status
        Temporary
        Financial
        Unfinancial
        Suspended
End Enum

    Private _PaidUpTo As Nullable(Of Date)

    Public Property PaidUpTo() As Nullable(Of Date)
        Get
            Return _PaidUpTo
        End Get
        Set(ByVal value As Nullable(Of Date))
            _PaidUpTo = value
        End Set
    End Property

    Public ReadOnly Property CurrentStatus() As Status
        Get
            If Not Me.PaidUpTo.HasValue Then Return Status.Temporary
            If Me.PaidUpTo.Value > Now Then
                Return Status.Financial
            Else
                If Me.PaidUpTo >= Now.AddMonths(-3) Then
                    Return Status.Unfinancial
                Else
                    Return Status.Suspended
                End If
            End If
        End Get
    End Property
End Class

As you can see from the code snippet, four code paths need to be tested for the CurrentStatus property. If you were to perform the unit testing manually, you would have to create a separate SubscriptionTest class, either in the same project or in a new project, into which you would manually write code to instantiate a Subscription object, set initial ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional Visual Studio® 2010

Professional Visual Studio® 2010

Nick Randolph, David Gardner, Michael Minutillo, Chris Anderson

Publisher Resources

ISBN: 9780470229880Purchase book