I am creating a unit test that will test company information into the system but so I can test various assertions in my test.
Here is the code I wrote:
public static Random randnum = new Random();
private string _company = DateTime.Now.ToString("dd/MM/yy ") + ("company") + randnum.Next().ToString();
Basically I am just trying to get a random number to generate with each assertion where the company is listed. So am I writing this wrong or did I forget a piece?
I am using MBUnit.
Please help!
Rewrite your unit test to use the following.
I suspect your issue is with Immutability (Immutable object). You are setting a private _company field with an initial value. Calls to this value wont regenerate the random number but instead use the value created when this class was instantiated.
Here is a good link which I found interesting regarding random numbers.
How do I seed a random class to avoid getting duplicate random values