Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

VSTS Unit Testing

Back to Forum: Tech Off
  • User profile image
    dlausch

    I have created a simple Win app which contains a form with a button (called Button1) and textbox (called TextBox1). The logic is such that when I click the button the contents of the textbox is assigned to "Hello". When I create a test project based on the button clicked event, the following code is generated:

    <TestMethod()> _

    Public Sub Button1_ClickTest()

    Dim target As Form1 = New Form1

    Dim accessor As TestAppWin_Form1Accessor = New TestAppWin_Form1Accessor(target)

    Dim sender As Object = Nothing 'TODO: Initialize to an appropriate value

    Dim e As EventArgs = Nothing 'TODO: Initialize to an appropriate value

    accessor.Button1_Click(sender, e)

    Assert.Inconclusive("A method that does not return a value cannot be verified.")

    End Sub

    When I change the last line of the Sub to the following:

    Assert.AreEqual(accessor.TextBox1.Text, "Hello")

    I get the following error when I run the Button1_ClickTest test:

    Failed Button1_ClickTest TestProject1 Test method TestProject1.Form1Test.Button1_ClickTest threw exception:  System.MissingFieldException: Field 'TestAppWin.Form1.TextBox1' not found.. 

    Does anyone know how to resolve this error? TIA.

    dlausch



  • User profile image
    out180

    Is your accessor codegen file out of sync?  I notice that sometimes the vscodegenaccessor file gets out of sync.  (ie. you rename TextBox1 to firstName)

    You can delete the codegen acessor file and recreate it via a right click within the Form1 class file in the IDE.

  • User profile image
    vandil

    I would try changing it to Assert.AreEqual(target.TextBox1.Text, "Hello")

    but I'm not sure if the accessabilty level of TextBox1 would permit that.

  • User profile image
    dlausch

    Thanks for the assistance but I finally discovered that my issue was a result of a bug in VSTS. The background can be found at:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=15094&SiteID=1

    dlausch

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.