I created NUnit Theory to help me verify the code. The actual verified code is not as important to this issue as the data that I use to verify it. Namely, hours and minutes of time in 24-hour mode.
I wrote my tool in such a way as to take advantage of the capabilities and comply with the restrictions in the function of NUnit 2.6 Theory. In particular, I felt that I needed to create classes such as “Hour” and “Minutes” to bypass the function that Datapoints map to arguments with the exact type.
[TestFixture] public class TimeWindowParserTheoryFixture { public class Hour { public int Value; } public class Minute { public int Value; public string AsString { get { return Value.ToString("00"); } } } [Datapoints] public IEnumerable<Hour> Hours { get { return Enumerable .Range(0, 25) .Select(v => new Hour() { Value = v }) .Union(Enumerable.Repeat((Hour)null, 1)); } } [Datapoints] public IEnumerable<Minute> Minutes { get { return Enumerable .Range(0, 60) .Select(v => new Minute() { Value = v }) .Union(Enumerable.Repeat((Minute)null, 1)); } } [Datapoints] public IEnumerable<string> Separators { get { return new[] { " ", "-" }; } } [Theory] public void ValidHours(Hour startHour, Minute startMinute, Hour endHour, Minute endMinute, string separator) { Assume.That(startHour != null); Assume.That(endHour != null); var parser = new TimeWindowParser(); var startMinutesString = String.Format("{0}{1}", startMinute == null ? "" : ":", startMinute == null ? "" : startMinute.AsString); var endMinutesString = String.Format("{0}{1}", endMinute == null ? "" : ":", endMinute == null ? "" : endMinute.AsString); var pattern = String.Format("{0}{1}{2}{3}{4}{5}{6}", startHour, startMinutesString, "", separator, endHour, endMinutesString, "");
What I found is that the size of the data set created during the default combinatorial logic of NUnit causes the file size to be so large that I run out of memory. This is not like I set up my test, and the data should be a problem, but since this is obviously the case, I ask for advice on how to think about this problem differently. Here is the OutOfMemoryException stack trace that I get.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Text.StringBuilder.ExpandByABlock(Int32 minBlockCharCount) at System.Text.StringBuilder.Append(Char* value, Int32 valueCount) at System.Text.StringBuilder.AppendHelper(String value) at System.Text.StringBuilder.Append(String value) at NUnit.Core.MethodHelper.GetDisplayName(MethodInfo method, Object[] arglist) at NUnit.Core.Builders.NUnitTestCaseBuilder.BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms)
This exception is odd in itself in the sense that it is thrown by simply trying to get the name of the Test method (see GetDisplayName). I am not sure if this is a mistake (known or otherwise). BTW, I get a very similar OOM exception when I overwrite this fixture using the less experimental Range and Value attributes used in parameter tests.