|
What is a Monte Carlo simulation?
On first hearing the notion of a simulation based on chance, you may think of never winning at the roulette. However the technique should be viewed from the point of the Casino. They also have no idea which number the ball is going to land on next. Even the next 100 rolls will be difficult to predict. What the casino does know though is that if the wheel is spun 30 million times, there will be one million each of 1,2,3 etc. As each spin is an independent act of chance, it is impossible to predict in which order the numbers will come. This predictability allows us to generate transactions that mirror the real world, I.e. we can simulate user activity for the Software Under Test (SUT). The randomness displayed on the roulette table can be displayed in many situations including stock prices, weather and behaviour of website users. When is it used?
The most common use in Software testing would be I suggest with performance testing. How is the data generated?
An example is to use the normal distribution. In the real world we know that we never get exactly the same probabilities for such as on roulette. Thus we have to use some other method of generating variability. Interest rates are a good test. Of course there are periods where they are at the extremes of 1-2% or 12% plus. However these are rare. Over a 25 year mortgage they are likely to be in the 5-8% range. (These are not accurate real world figures.) Thus if we are to calculate transactions on hundreds of mortgages with different rates, we need most of them to be in 5-8% interest, but some will be at the extreme. The table below shows a spreadsheet calculation. The first row is the Normal Distribution for a given amount. (This calculation is not discussed here.) The second is the percentage of cases that will use the interest rate. The cumulative number of cases is 4th and the interest rate used is last. As we can see the majority of test inputs will be in the 4.5% - 8.5% range. This mirrors real life.
Thus 4141 of transactions will involve an interest rate of 4.5%. 0.5% will the rate in only 6 cases out of 50,000. The alternative is to generate a random number and according to a defined set of rules set the case input accordingly. |
Load Testing Bestsellers
The bestselling books on Amazon.
Articles
Other Related Websites
Automated Testing
Nonfunctional Testing