Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:02:52+00:00 2026-05-26T01:02:52+00:00

I am currently working on a C# project. I have just started needing to

  • 0

I am currently working on a C# project. I have just started needing to learn how to do unit tests and am finding them pretty difficult to get my head around some parts of it. I have a function which returns a List array and I need to test this method is working correctly.

When I right click on the method in VS2010 and say create Unit Test it creates me the following code:

    [TestMethod()]
    public void readStreamTest()
    {
        ReadStream target = new ReadStream(); // TODO: Initialize to an appropriate value
        Stream stream = new MemoryStream(); // TODO: Initialize to an appropriate value
        StreamWriter sw = new StreamWriter(stream);

        string line = "My Line 1\n¬My Line 2\nMy Line 3\nMy Line 4\nMy Line 5\nMy Line 6\nMy Line 7";
        int numLines = 5; // TODO: Initialize to an appropriate value
        List<FileLine> lines = new List<FileLine>();
        int i = 0;
        while ( i != 7 )
        {
            lines.Add(new FileLine()
            {
                lineNo = i,
                lineContent = line
            });
            i++;
        }
        List<FileLine> expected = lines; // TODO: Initialize to an appropriate value
        List<FileLine> actual;
        actual = target.readStream(stream, numLines);
        //Assert.AreEqual(expected, actual);
        Assert.IsNotNull(expected);
    }

Some of it, like the initialisation of the list and adding items to the list using the array is what I have added myself to try and figure out what to do.

If anyone can provide any help on how I could test this, I don’t see how it can work with a list array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:02:53+00:00Added an answer on May 26, 2026 at 1:02 am

    Let’s solve your problem first, and then we can talk general testing pointers.

    Assert.AreEqual is going to compare for reference equality, which is not what you want. What you really want is to compare that the contents are the same (I assume). This can be done using the Enumerable.SequenceEqual method like so:

    Assert.IsTrue(expected.SequenceEqual(actual));
    

    Now we can talk more generally about testing. I have posted about this before, but I’ll try to summarize the theme here.

    Focus on Behavior!

    Unit testing should be about behavior, not implementation details! This is the first and most basic principle in my opinion. It will inform every other decision you make.

    Why is this such a big deal?

    Because if you don’t do this, then your tests will be brittle. Changing the implementation details will break the tests, and that shouldn’t happen. Your unit tests should free you up to be able to refactor and improve the code with confidence. If your tests are tied to the implementation details this can’t happen, and you will always be fighting against your tests.

    So what does this look like? Well lets compare two hypothetical tests:

    [TestMethod]
    public void TestThatUserInfoIsValidatedAndSaved()
    {
        var user = new User{Name = "Bob"};
        UserService.SaveUser(user);
    
        //Check that data access got called to see if Bob exists
        //Check that validation got called
        //Check that data access got called to save bob
    }
    
    [TestMethod]
    public void ShouldSaveNewUser()
    {
        var user = new User{Name = "Bob"};
        UserService.SaveUser(user);
    
        //Check that bob was saved
    }
    

    In the preceding two methods, one is very granular in testing specific details about the method, while the other simply tests the intended behavior. If we change how that method works under the hood, then the first will break. However, the second test should continue to work just fine.

    Your tests should describe “What” the system does, not “how” it does it.

    Do this and you will have a much better experience with unit testing in the long run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a school project in Eclipse (We have just started using
I have just started working with a new Coldfusion project, well the project is
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I have a project that I'm currently working on but it currently only supports
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
In the project I am currently working on, we have the need to develop
Hi Currently i am working on a rails project . where i have to
I have been working on keeping things object oriented for my project. Currently, I'm
I have just started working with a new company in a very small IT
I just started working on a project that was developed in Visual C++ 2005

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.