views:

312

answers:

3

I'm running a NUnit test over a list of numbers.

My code goes something like this:

numbers = GetListOfNumbers()
foreach number in numbers
      Assert.IsTrue(TestNumber(number))

My problem is that NUnit will stop the test on the first number it encounters that doesn't pass the test.

Is there anyway to make NUnit still fail the test if any numbers don't pass, but give me the list of all numbers that don't pass?

A: 

This can be done in MBUnit using a "RowTest" test method. I'm not aware of a way of doing this in NUnit, however.

GalacticCowboy
With MbUnit v3, you can also use the not so well known "Assert.Multiple(() => { ... })".
Yann Trevin
+5  A: 

NUnit 2.5 has data-driven testing; this will do exactly what you need. It'll iterate over all of your data and generate individual test cases for each number.

Link

Mark Simpson
Sweet! I had never seen that. (Of course, I haven't looked at NUnit in quite a while - I mostly use MBUnit and MSTest...)
GalacticCowboy
I'm already kind of doing that. I have about 30 files and each file can have up to 40 000 numbers in it. I'm using the TestCaseSource attribute to generate a test per file. To generate a test for each number would be far too slow and cumbersome.
Ray
So you really need to test 700,000 numbers regularly?
GalacticCowboy
Well it's more like 250 000, not every file has 40 000. But yeah, I need to check my routine which checks those numbers are valid. And it can't make any previously valid number invalid because that would cause problems.
Ray
+5  A: 

As a workaround, instead of using an Assert.IsTrue like that, you could try something like:

numbers = GetListOfNumbers()
List<number> fails = numbers.Where(currentNum=>!TestNumber(curentNum))
if (fails.Count > 0)
    Assert.Fail(/*Do whatever with list of fails*/)
GWLlosa
currentNum => !TestNumber(currentNum)
GalacticCowboy
Whoops! Good catch, fixed.
GWLlosa