# Expected values in software testing

Expected  values are valuable in statistics and in software testing.

However, they generally mean different things. How do they differ, and how can one be applied to the other?

### What is expected value?

Expected value is also referred to as EV or Expectation.

It's basically what you'd expect the value of a random variable to be if you did the experiment an infinite number of times and then averaged those values.

In statistical terms, the "[e]xpected value is a measurement of the center of a probability distribution."

Because the expected value is more like a weighted average, the random variable generally does not take on the expected value.

### Okay, but what's a random variable?

A random variable is also known as a stochastic variable.

It's a variable whose value varies due to... well, randomness or chance. 🙂

Flipping a coin or rolling dice are 2 classic examples of random variables. You can look at it as an experiment where the outcome is governed by chance.

Flipping a coin is the experiment, and the outcome of heads vs. tails is governed by chance.

### What is the relationship between the expected value and the Law of Large Numbers?

"...the law of large numbers (LLN) is a theorem that describes the result of performing the same experiment a large number of times."

When flipping a coin, you may get 5 heads in a row.

However, if you flip the coin an infinite number of times, the theorem says that on average you will approach the point where you have an equal number of heads and tails.

Keep in mind, this is different than saying that you will get 5 tails to counteract the 5 heads you just got!

The LLN relates to the expected value, because the mean of your experiments will approach the expected value as the number of experiments grows to infinity.

### How does the expected value in statistics differ from the expected value in software testing?

We've briefly looked at what the expected value is in statistics.

In software testing, the expected value is generally what we expect to see *every* time we execute a test or experiment.

This differs from the expected value of a test case. The expected value in statistics relies on the Law of Large Numbers.

With a large enough sample, the sample approaches the expected value. The expected value in software testing is normally a value or result that the test or experiment is expected to take on.

### How can the expected value be used in software testing?

The expected value from statistics can be used to model performance and reliability in software testing.

The performance of a system is not always the same. We can specify a distribution which models what we think the user will experience.

For example, it cannot be set in stone that every user will have a page load time of 10 secs. Page load times vary depending on network traffic, time of day and an endless number of other variables.

If a large enough number of performance experiments are carried out, the expected value can be derived by averaging the results of the experiments.

This expected value can be one measurement of the page load time when a software tester is attempting to determine or report on the performance of a software system.

A similar argument can be made for the reliability of a system.