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.5. Advanced

Up until now, you have seen how to write and execute unit tests. This section goes on to examine how you can add custom properties to a test case, and how you can use the same framework to test private methods and properties.

20.5.1. Custom Properties

The testing framework provides a number of test attributes that you can apply to a method to record additional information about a test case. This information can be edited via the Properties window and updates the appropriate attributes on the test method. There are times when you want to drive your test methods by specifying your own properties, which can also be set using the Properties window. To do this, add TestProperty attributes to the test method. For example, the following code adds two attributes to the test method to enable you to specify an arbitrary date and an expected status. This might be convenient for ad hoc testing using the Test View and Properties window:

<TestMethod()> _
<TestProperty("SpecialDate", "1/1/2008")> _
<TestProperty("SpecialStatus", "Suspended")> _
Public Sub SpecialCurrentStatusTest()
    Dim target As Subscription = New Subscription

    target.PaidUpTo = CDate(Me.TestContext.Properties.Item("SpecialDate"))
    Dim val As Subscription.Status = _
   CType([Enum].Parse(GetType(Subscription.Status), _
   CStr(Me.TestContext.Properties.Item("SpecialStatus"))), _
             Subscription.Status)

    Assert.AreEqual(val, target.CurrentStatus, _
                    "Correct status not set for Paid up date {0}", target.PaidUpTo)
End Sub
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