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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:35:05+00:00 2026-06-13T16:35:05+00:00

assume you have a unit test that contains these lines assertNotNull(someVal); assertNotEmpty(someVal); This obviously

  • 0

assume you have a unit test that contains these lines

assertNotNull(someVal);
assertNotEmpty(someVal);

This obviously checks that someVal is not null and is populated with something.

The question is, is the first line necessary and does it add anything to the test? Should we not just have the second line, and if it’s null it will throw a null pointer exception which still indicates a failing unit test (but not a failing assertion).

What’s the best practice in such simple cases?

  • 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-13T16:35:06+00:00Added an answer on June 13, 2026 at 4:35 pm

    I’m not a big fan of assertNot()‘s and more generally testing unexpected things that could happen to the SUT, let alone testing them in addition to the normal Assert in every single test.

    IMO you should only test for nominal states of your objects. If it is normal for someVal to be null in some circumstances, then create a dedicated test method checking that it is indeed null in that scenario. Choose an intention-revealing name for your test, like someValShouldBeNullWhen...(). Do the same for empty, or any other value.

    You see that unexpected things happen to your SUTs by looking at your tests exception messages, not by trying to forecast each of these unexpected things in advance and cramming your tests with assertNots for them.

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

Sidebar

Related Questions

Assume I want to unit test a method with this signature: List<MyItem> getMyItems(); Assume
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----
Assume I have the following ; def test(): while 1: a = b time.sleep(60)
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
I need to create a unit test for a method that returns an xmldocument.
I have a simple unit test where I execute the same NHibernate named query
How do you unit/integration test code that requires a different privilege level than exists
Assume I want to write a unit test to test a particular piece of
I want to be able to have two projects, one that contains production code

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.