question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expect random number but everytime is the same with Nunit

See original GitHub issue
       [Test]
        [Repeat(10)]
        [AutoData]
        public void TestIt(int a,int b)
        {
            Assert.Positive(a + b);
        }

I use repeat attribute to let the method run 10 times,and I expect each time both a and b have different values but I got the same value 10 times.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrtylerzhoucommented, Jun 6, 2018

thank you for you suggestion,I’ll have a try

0reactions
zvirjacommented, Jun 5, 2018

to increase the randomness of test.

Well, it’s more about the desirable behavior, rather than explanation why the current behavior is incorrect 😉

If you wish, you could easily implement your own AutoData attribute that will have e.g. Repeat property. Use the existing implementation as a base.

Please let me know if you need my further assistance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Same random number generated when run in test Fixture ...
I am trying to generate a random number during testing using NUnit, but it keeps generating the same number. I am using the...
Read more >
Repeatable Random Tests with Fixed/Additional Seed #1461
To generate random numbers within the test, using TestContext.Random. Strictly speaking, the test Seed is used to generate another seed for use ...
Read more >
Is the usage of random values in unit testing a good practice?
The source of the data may have been random but because the same data is reused for each run, the test is deterministic....
Read more >
Randomizer Methods
Random to provide random data for a wide range of numeric types as well as enums and strings. Each test context has access...
Read more >
Why Are My C# Random Numbers Not Random?
So I have this code, which is supposed to generate a new random number every time it is called: public static int GetSomeRandomNumber(int ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found