Random data testing has been around for ages and every now and then our Test Studio support team gets a request like this:
How can I input random data into my test run?
But then comes the next field, the next value. “Oh this is a number, but I need email, telephone… etc.” Then you will probably think about reusability but there is a pretty big chance that eventually you will have this little code noodle monster spread across the entire project.
So, how we can prevent that? I’ve been tinkering with “Any-.Net”, a simple old framework for generating all sorts of random data and it seems to be solving the issue pretty well.
So, let’s integrate it in Test Studio:
1. Download “Any-.Net” and add it as a script reference to your Test Studio project:
2. Create a simple test that will act as a reusable container for random data. I will call it “SetRandomValues.”
3. Open the “SetRandomValues” test and add a coded step to it:
4. Time to integrate the Any-.Net framework into our project. This will be the only piece of code that you’ll ever require:
[CodedStep(@"New Coded Step")]
public void SetRandomValues_CodedStep()
this.SetExtractedValue("randomInt", Any.Any.Integer(0, 100));
Now whenever you need a random value you can simple reference the “SetRandomValues” as test as a step:
That’s it! Having a single test as a random value generator reduces complexity and maintenance. On top of that all values are bound via the built-in functionality, so it doesn’t require any coding.
If you want to try this you can start a free, fully functional 30-day trial:
Nikolay is an Engineering Manager on the Test Studio team. He is passionate about quality code, snowboarding and video games.
Subscribe to be the first to get our expert-written articles and tutorials for developers!