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 1074163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:05:08+00:00 2026-05-16T21:05:08+00:00

I am relatively new to using TDD and have been reading about mocking objects

  • 0

I am relatively new to using TDD and have been reading about mocking objects lately. I have the following test to test a method that given a date returns the next saturday.

[TestMethod()]
        public void NextSaturdayTest()
        {
            DateTime date = new DateTime(); 
            date = DateTime.Parse("2010-08-14");
            DateTime expected = new DateTime(); 
            expected = DateTime.Parse("2010-08-21");
            DateTime actual;
            actual = DateExtensions.NextSaturday(date);
            Assert.AreEqual(expected, actual);

            date = DateTime.Parse("2010-08-19");
            expected = DateTime.Parse("2010-08-21");
            actual = DateExtensions.NextSaturday(date);
            Assert.AreEqual(expected, actual);
        }

first off, does this represent good testing practices?
Second, what is the advantage of utilizing a mock framework to create this test?

Let me know if I can offer any more information.

Thanks for any thoughts

  • 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-16T21:05:09+00:00Added an answer on May 16, 2026 at 9:05 pm

    First, don’t do this:

    DateTime date = new DateTime();
    date = DateTime.Parse("2010-08-14");
    

    You are creating a new datetime, then throwing it away when you parse a string to get a new datetime.Remember, test code should still be good code.

    Second, a good test tests one thing. You may have multiple tests like ReturnsCorrectNextSaturdayGivenAWednesday, ReturnsCorrectNextSaturdayWhenCrossesEndOfMonth, and ReturnsCorrectNextSaturdayWhenCrossesEndOfYear.

    And finally, there’s no reason to mock here. A mock would be appropriate if your DateExtensions called into another component (say a database), and you wanted to fake that call. So instead of testing DateExtensions + Data Access, you’d only be testing the DateExtensions and when it called the data access layer, it would be a mock that your test set up.

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

Sidebar

Related Questions

I'm relatively new to PHP and have been writing a project using what I
I'm relatively new to OpenGL and have been using the GLTools library it provides.
I'm relatively new to Vim and have been using it without issues so far.
I'm relatively new to NHibernate, but have been using it for the last few
I'm relatively new to using PHP and have been working on using it to
I have started using SqLite recently, so I am relatively new to it. I
I am relatively new to using jQuery and I have a problem with creating
I am 'relatively new' to unit-testing and TDD. Only more recently have I completed
I'm relatively new to objective-c...I'm using the iphone 3.0 SDK I have a UIView,
I'm relatively new to .NET and have being using Linq2Sql for a almost a

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.