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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:27:40+00:00 2026-05-16T23:27:40+00:00

Say, I have the following test: [Test] public void MyTest( [RandomNumbers( Count=100, Minimum=0, Maximum=1000

  • 0

Say, I have the following test:

    [Test]
    public void MyTest( [RandomNumbers( Count=100, Minimum=0, Maximum=1000 )] int number )
    {
        ...
    }

And at some point, during my regular build process, it has failed. I got an e-mail notification and set off to investigate.

Now, when I open the test in Visual Studio and click “Run Tests”, it passes. I do it again, and it passes again. And again. And again. Obviously, the failure was related to that particular sequence of random numbers.

So the question is: How do I re-run this test with that exact sequence?
(provided I have full Gallio report)

 
 
UPDATE:
(following a comment about it being a bad idea)

First, I’m not actually asking whether it’s a good idea. The question is different.

Second, when the system being tested is complex enough, and the input data space is of multiple independent dimensions, properly breaking that space into equivalency regions presents a significant challenge in both mental effort and time, which is just not worth it, provided smaller components of the system have already been tested on their own. At the same time, if I can just poke the system here and there, why not do so?

Third, I am actually not a newbie in this area. I always used this technique with other test frameworks (such as csUnit and NUnit), and it proved very successful in catching subtle bugs. At the time, there was no such concepts as generated data, so we used our own custom crutches, in the form of System.Random with a predetermined seed. That seed was being generated as part of fixture initialization (usually based on current time) and carefully written to log. This way, when the test failed, I could take the seed from log, plug it into the test fixture, and get exactly same set of test data, and thus, exactly same failure to debug.

And fourth, if it is such a bad idea, why does the RandomNumbers factory exist in the first place?

  • 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-16T23:27:41+00:00Added an answer on May 16, 2026 at 11:27 pm

    There is currently no built-in way in Gallio/MbUnit to generate again the same sequence of random numbers. But I think this could be a useful feature and I did open an issue for that request. I’m going to update the subject answer when it’s ready.

    What I propose is the following:

    • Display the actual seed of the inner random generator as an annotation into the test report.
    • Expose a Seed property to the [RandomNumbers] and [RandomStrings] attributes, and to the fluent data generators as well.

    Thus you could easily re-generate the exact same sequence of values by feeding the generator with the same seed number.

    UPDATE: This feature is now available in Gallio v3.3.8 and later.


    Now we all agree with what Péter said. Using random numbers as input for unit tests is rarely a good idea. The corollary is that it is sometimes convenient and mostly appropriate. And that is exactly the reason why we decided to implement that feature in MbUnit. IMHO, a common scenario that could fit well with random test input is stochastic analysis on hash code computations.

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

Sidebar

Related Questions

Say I have the following methods: public static void MyCoolMethod(params object[] allObjects) { }
Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
Lets say i have the following controller: // // GET: /Courses/Edit/5 public ActionResult Edit(int
Say I have a struct declared like the following: public struct Test { public
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
Say I have the following models: public class Item { public int Id{ get;
Say I have the following: [Test] // would like to parameterize the parameters in
Say I have the following chef role: name test description role for test run_list
Let say I have the following data in R. training = factor(c(1,1,3,2,1,3,2,34,67,34)) test =
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0

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.