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

  • Home
  • SEARCH
  • 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 8429855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:27:07+00:00 2026-06-10T05:27:07+00:00

I have a small method which return true or false if a timestamp is

  • 0

I have a small method which return true or false if a timestamp is a weekend day i.e. saturday or sunday.

Now i am very new to unit testing and i am trying to write a unit test for this.

In my test case, how would i proceed:

Here is my inital thinking.

1. Pick any 1 week from the past and then...
   1.1. Get a timestamp for all 5 week days (mon through fri) and pass each timestamp to the function being tested.  If they all return false then proceed...
   1.2  Get the timestamp for both weekend days and pass each to function being tested.  If they both return true then we know the function is correct.

or

2  Simply pick 1 weekday from the past and 1 weekend day from the past and test with only those 2 dates

Am i correct in either of these approaches or is there a better way to test this?

  • 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-06-10T05:27:08+00:00Added an answer on June 10, 2026 at 5:27 am

    If you put several checks into a single test, you will have the problem that you won’t know what some of the checks might return when one of the first ones fails. Say the method fails for day #3. Would it work for day #4? This information could be very useful when trying to find the bug.

    My approach is to test all values at once. It works like this:

    1. Select a date in the past
    2. Create a loop which advances the date 8 times by one day
    3. Call the method for each date and append the result to a string
    4. Create a string with the expected result by looking at a real calendar)
    5. Compare the two strings

    This way, you can see with a single glance for which dates the method fails.

    The other option is to write 8 tests and have each test check a single date.

    Tip: Tests like this tend to fail when timezones are introduced. Create more tests which use timestamps that are close to midnight and play with the timezome. Is the result still correct?

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

Sidebar

Related Questions

I create small application which is media player. I have method where I have
I have written a small webservice[Axis2/Java] which exposes a method public String Fill(String cacheName
I have a small issue with a method that should save the text contained
have small problem, and would very much appreciate help :) I should convert byte
I have small script in bash, which is generating graphs via gnuplot. Everything works
I have small test app: Socket socket = new Socket(jeck.ru, 80); PrintWriter pw =
I have a UIScrollView which contains some small UIView subclass. UIScrollView is scroll enabled,
I have Delphi lib which must return information read via socket. function GetBufferInfo(Address: PChar):
I have a small application which consists of a DAL, BLL and the Application
I have a small problem which I can't seem to find a solution to.

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.