CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Question about C# unit tests

    Hello!

    I am relatively new to C# and I am currently working as a software QA at a .net shop. I'm interested in writing unit tests using the framework built into Visual Studio 2010 and I loosely followed this tutorial http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx

    Here is the code I am writing:

    /// <summary>
    ///A test for LoginInfo Constructor
    ///</summary>
    [TestMethod()]
    public void LoginInfoConstructorTest()
    {

    string userId = "Username1";
    string password = "Password1";

    LoginInfo target = new LoginInfo(userId, password);

    Assert.AreEqual<string>(userId, loginInfo.UserId,
    "The UserId was not correctly initialized.");

    }

    When I write this, I receive an error that says "The name 'loginInfo' does not exist in the current context". I don't understand why it is telling me this when 'loginInfo' is defined in the code above. What am I doing wrong?

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Question about C# unit tests

    You have not defined loginInfo. You have defined a variable called target of type LoginInfo.

    At a guess, is your code meant to read...
    Code:
    Assert.AreEqual<string>(userId, target.UserId, "The UserId was not correctly initialized.");
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Question about C# unit tests

    Inside your uinit test project, you'll need to add a reference to the code you are trying to test.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured