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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:17:18+00:00 2026-05-10T14:17:18+00:00

I have a coworker who writes unit tests for objects which fill their fields

  • 0

I have a coworker who writes unit tests for objects which fill their fields with random data. His reason is that it gives a wider range of testing, since it will test a lot of different values, whereas a normal test only uses a single static value.

I’ve given him a number of different reasons against this, the main ones being:

  • random values means the test isn’t truly repeatable (which also means that if the test can randomly fail, it can do so on the build server and break the build)
  • if it’s a random value and the test fails, we need to a) fix the object and b) force ourselves to test for that value every time, so we know it works, but since it’s random we don’t know what the value was

Another coworker added:

  • If I am testing an exception, random values will not ensure that the test ends up in the expected state
  • random data is used for flushing out a system and load testing, not for unit tests

Can anyone else add additional reasons I can give him to get him to stop doing this?

(Or alternately, is this an acceptable method of writing unit tests, and I and my other coworker are wrong?)

  • 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-10T14:17:18+00:00Added an answer on May 10, 2026 at 2:17 pm

    There’s a compromise. Your coworker is actually onto something, but I think he’s doing it wrong. I’m not sure that totally random testing is very useful, but it’s certainly not invalid.

    A program (or unit) specification is a hypothesis that there exists some program that meets it. The program itself is then evidence of that hypothesis. What unit testing ought to be is an attempt to provide counter-evidence to refute that the program works according to the spec.

    Now, you can write the unit tests by hand, but it really is a mechanical task. It can be automated. All you have to do is write the spec, and a machine can generate lots and lots of unit tests that try to break your code.

    I don’t know what language you’re using, but see here:

    Java http://functionaljava.org/

    Scala (or Java) http://github.com/rickynils/scalacheck

    Haskell http://www.cs.chalmers.se/~rjmh/QuickCheck/

    .NET: http://blogs.msdn.com/dsyme/archive/2008/08/09/fscheck-0-2.aspx

    These tools will take your well-formed spec as input and automatically generate as many unit tests as you want, with automatically generated data. They use ‘shrinking’ strategies (which you can tweak) to find the simplest possible test case to break your code and to make sure it covers the edge cases well.

    Happy testing!

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

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, if by 3 you mean the method under inspection… May 12, 2026 at 2:27 pm
  • Editorial Team
    Editorial Team added an answer Using Linq to XML : var doc = XDocument.Parse(xmlAsString); var… May 12, 2026 at 2:27 pm
  • Editorial Team
    Editorial Team added an answer I'll quote Martin Fowler here, since I think his meaning… May 12, 2026 at 2:27 pm

Related Questions

I'm asking because PowerShell confuses me. I've been trying to write some deployment scripts
I have a co-worker that swears by //in a singleton Constants class public static
I have a coworker who is looking to switch from InteilliJ Idea to Eclipse,
My Google-fu is failing me on this question. I have a coworker who has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.