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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thank you for you suggestion,I’ll have a try
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.