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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:41:26+00:00 2026-06-11T12:41:26+00:00

This is a very basic question but I still cannot find the appropriate answer.

  • 0

This is a very basic question but I still cannot find the appropriate answer. In my test there is a possibility to have null values and because of that the last stage (Act) starts looking a little bit strange (it is no longer act only). What I mean is the following:

Assert.IsNotNull(variable);

var newVariable = variable.Property;
Assert.IsNotNull(newVariable);

var finalVariable = newVariable.AnotherProperty;
Assert.AreEqual(3, finalVariable.Count);

Now they are obviously related and I have to be sure that the values are not null, but also there are three asserts in one test and the act part starts to look not right.

So what is the general solution in such cases? Is there anything smarter than 3 tests with one assert each and checks for null before the asserts of the last 2?

  • 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-11T12:41:27+00:00Added an answer on June 11, 2026 at 12:41 pm

    Basically there are two ways of dealing with your problem:

    1. Guard assertions: extra asserts making sure data is in known state before proper test takes place (that’s what you’re doing now).
    2. Moving guard assertions to their own tests.

    Which option to chose largely depends on code under test. If preconditions would be duplicated in other tests, it’s a hint for separate test approach. If precondition has reflection in production code, it’s again hint for separate test approach.

    On the other hand, if it’s only something you do to boost your confidence, maybe separate test is too much (yet as noted in other answers, it might be a sign that you’re not in full control of your test or that you’re testing too many things at once).

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

Sidebar

Related Questions

This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
Please forgive this rather basic question, but I'm very new to Java and still
This is a very basic question - but I haven't been able to find
I guess that this is a very absurd/basic question, but still: class m {
This may be a very basic question, but it still gets me confused (and
I know this is a very basic question but I have kinda been thrown
I realize that this is probably a very basic question, but I have spent
I understand this question may sound very basic but I have been trying to
This might be a very basic question but it confuses me. Can two different
I know, this might be a very basic question but I am not 100%

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.