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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:34:43+00:00 2026-05-13T20:34:43+00:00

I hope this doesn’t come across as a stupid question but its something I

  • 0

I hope this doesn’t come across as a stupid question but its something I have been wondering about. I wish to write unit test a method which contains some logic to check that certain values are not null.

public void MyMethod(string value1, string value2)
{
    if(value1 != null)
    {
     //do something (throw exception)
    }

    if(value2 != null)
    {
     //do something (throw exception)
    }

    //rest of method
}

I want to test this by passing null values into the method. My question is should I create a unit test for each argument or can I create one unit test which checks what happens if I set value1 to null and then checks what happens if I set value2 to null.

i.e.

[TestMethod]
public void TestMyMethodShouldThrowExceptionIfValue1IsNull()
{
    //test
}

[TestMethod]
public void TestMyMethodShouldThrowExceptionIfValue2IsNull()
{
    //test
}

or

[TestMethod]
public void TestMyMethodWithNullValues()
{
  //pass null for value1
  //check

  //pass null for value2
  //check
}

Or does it make any difference? I think I read somewhere that you should limit yourself to one assert per unit test. Is this correct?

Thanks in advance
Zaps

  • 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-13T20:34:44+00:00Added an answer on May 13, 2026 at 8:34 pm

    You should write a unit test for each test case (assertion) to avoid Assertion Roulette.

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

Sidebar

Related Questions

i hope this question is not too simple, but i have no idea :(
I hope this question does not come off as broad as it may seem
I hope this question is not considered too basic for this forum, but we'll
(Hope this doesn't get duplicated; second attempt at submitting this question) I'm working on
Sorry, but I know nothing at all about fonts, so I hope that this
I hope this makes sense... It doesn't only apply to c#, but that is
I hope this hasn't been asked and I just missed it, but I searched
I hope this is programmer-related question. I'm in the hobby business of C# programming.
I hope this is a simple enough question for any SQL people out there...
I hope this question is not a RTFM one. I am trying to write

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.