I'm just trying out tdd with nunit and i've written the following test, for my CachedEnumerable<T>
class:
[Test]
public void CanNestEnumerations()
{
var SourceEnumerable = Enumerable.Range(0, 10).Select(i => (decimal)i);
var CachedEnumerable = new CachedEnumerable<decimal>(SourceEnumerable);
Assert.DoesNotThrow(() =>
{
foreach (var d in CachedEnumerable)
{
foreach (var d2 in CachedEnumerable)
{
}
}
});
}
Will the nested for loops be optimised out, since they don't do anything (
CachedEnumerable
is never used after the loops)?Are there any (other?) cases where test code could potentially be optimised out?
If so, how can i ensure that the test code actually runs?