I'm not really sure what/if there is a gold-standard on how much a unit test should be broken down. Another thing is sometimes I question whether I am wasting my time on a specific test. I am new to unit testing/TDD. So for example, say I have some simple code like this:
public class IntegerStats
{
public int MaxValue { get; private set; }
public int MinValue { get; private set; }
public int NumberOfElements { get; private set; }
public double AverageValue { get; private set; }
public IntegerStats(int[] inputArray)
{
MaxValue = inputArray.Max();
MinValue = inputArray.Min();
AverageValue = inputArray.Average();
NumberOfElements = inputArray.Length;
}
}
My first two unit tests look like this:
[Test]
public void ProvideArrayReturnsIntStatsObject()
{
int[] testArray = {1, 5, 254783, 98, 4793, 67};
IntegerStats intStats = new IntegerStats(testArray);
Assert.IsTrue(intStats.GetType().ToString().Contains("IntegerStats"));
}
[Test]
public void Length5ArrayLengthIs5()
{
var result = new IntegerStats(new int[]{5,4,8,9,4});
Assert.AreEqual(result.NumberOfElements,5);
}
However, should I be passing multiple arrays in to this one test or should I make several array length tests of different lengths? How do I know if the method is adequately tested?
My next plans were to continue testing the other properties... But then I was questioning whether I should even be testing these methods since they are using built-in provided standard library algorithms rather than my own custom algorithms in the first place.
Also, I had first started out with a test checking whether all of the stats were accurate in one big test but then I realized that's not really a unit test since it could/should have been broken down more.
Any advice/resources on this would be super helpful. The thing is, I've done plenty of reading about "What unit testing is" but putting it into practice for me has been quite different.
new
keyword works.I was questioning whether I should even be testing these methods since they are using built-in provided standard library algorithms rather than my own custom algorithms in the first place.
-- As well you should. You should also be questioning whether such a class is even useful (other than as an intellectual exercise or example), since all you're really doing is replicating functionality that already exists as methods of the array object.