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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:53:19+00:00 2026-05-14T01:53:19+00:00

This is me going right back to basics with TDD for learning purposes. I

  • 0

This is me going right back to basics with TDD for learning purposes.

I originally implemented Person.Surname as field of type object (the simplest possible way of passing the test.

I then added a test setting Person.Surname stating that the return value should be a string and set Person.Surname=20.

I ‘fixed’ the test by changing the implementation to use string rather than object. The test now long compiles due to static type checking, so I commented it out.

Person.Surname field is currently implemented as a string. If I change the implementation of the field to an object, none of my tests fail.

So I’m left with no way of leaving my intention in the test. Is there a way of having a failing test in this circumstance?


Update:
I agree with Esko, that practically this isn’t something you want to be doing.
From a learning point of view, the point I was trying to make was that if I (or someone else at a later point in time) widens the type scope of my field (say from string to object) I won’t have any directly failing unit tests. Maybe this isn’t a bad thing afterall?

  • 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-14T01:53:19+00:00Added an answer on May 14, 2026 at 1:53 am

    Writing tests about a field having some type, is too low abstraction level. Write tests which describe features. Then the tests will better describe why the code was written, and you will be able to more freely refactor the implementation without breaking/invalidating existing tests.

    When refactoring the production code, every now and then it will affect also the test code and you need to update the tests to make them compile and pass (the test code requires refactoring the same as all other code). When that happens, it’s helpful that the name of the test tells that what was the intention behind the test – what feature/behaviour is being specified by the test. Then you can update the test code so that the same intention remains. Or if the reason for writing the tests is no longer valid, then you can remove the test.

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

Sidebar

Related Questions

Right, I know I am totally going to look an idiot with this one,
This is going to sound like a silly question, but I'm still learning C,
Wondering if I'm going about this the right way or not. I have 3
This is going to be the noobist of all noob questions, but what exactly
This is going to be hard to explain but I'll try my best. I
Is this functionality going to be put into a later Java version? Can someone
This is likely going to be an easy answer and I'm just missing something,
I know this one is going to be a long-shot, but I thought I'd
I may be going about this backwards... I have a class which is like
We currently use VSS 6, this is not going to change I am afraid.

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.