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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:43:30+00:00 2026-05-11T12:43:30+00:00

I am in the process of learning to unit test. I have a ‘domain

  • 0

I am in the process of learning to unit test. I have a ‘domain object’ that doesn’t do much apart from hold state (i.e. Employee without any business logic). It has a method SetDefaults() which just fills its state with reasonable values. A simple method.

But when I go to unit test this method all I can think of is to run the method then check that every field is what it should be. Like (in C#):

        [TestMethod()]     public void SetDefaultsTest()     {         Employee target = new Employee();          employee.SetDefaults();          Assert.AreEqual(employee.Name, 'New Employee');         Assert.AreEqual(employee.Age, 30);         // etc.     } 

It feels wrong to duplicate the entire functionality of SetDefaults() within my test. Should I just leave this method untested? The problem is that I’d like a test to ensure that when new properties are added to the class they are also added to the SetDefaults() method.

  • 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. 2026-05-11T12:43:31+00:00Added an answer on May 11, 2026 at 12:43 pm

    Trivial getters and setters sometimes don’t have unit tests written for them. If that’s all that SetDefaults() does, it probably won’t hurt to skip it.

    One thing you would want to consider testing, though, is that none of the set properties of the employee instance are null after calling SetDefaults():

    var nonNullProperties = new object[] { employee.Name, employee.Age, ... }; foreach (var property in nonNullProperties)   Assert.IsNotNull(property); 

    This makes sense, since you really just care that they are set to some default value, and not so much that they’re a specific value.

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

Sidebar

Related Questions

I'm in the process of learning Databases and SQL. From what I have read
I'm in the process of learning C++. But there's so much more that I
I'm in the process of learning WPF coming from WinForms development. I have a
I am in the process of learning the Yii Framework. I have been following
I am in the process of learning the CXF framework and I know that
I'm in the process of learning Node.js and have been playing around with Express
I am in the process of learning cocos2d-android. I have been following a tutorial
I am in the process of learning Backbone.js. I currently assume that if one
I am in the process of learning Python and I have reached the section
I'm in the process of learning JQuery, and I'm looking to have a list

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.