10

With MSpec is it possible to create data driven tests?

For example, NUnit has the TestCase attribute that allows for multiple data driven cases.

[TestFixture]
public class ExampleOfTestCases
{

  [TestCase(1,2,3)]
  [TestCase(3,3,6)]  
  [TestCase(2,2,4)]  
  public void when_adding_two_numbers(int number1, int number2, int expected)
  {
     Assert.That(number1 + number2, Is.EqualTo(expected);
  }
}
1

1 Answer 1

4

That's not possible. I would advise against driving MSpec with data, use NUnit or MbUnit if you need row tests or combinatorial tests (and MSpec when you describe behavior).

Follow-up: Aeden, TestCases/RowTests are not possible with MSpec and likely will never be. Please use NUnit for such cases, as it is the best tool for that job. MSpec excels when you want to specify system behavior (When an order is submitted => should notify the fulfilment service). For TestCases with MSpec you would need to create a context for every combination of inputs which might lead to class explosion.

MSpec is also great when you want to have a sane test structure that is easy to learn. Instead of starting with a blank sheet of paper (think NUnit's [Test] methods) MSpec gives you a template (Establish, Because, It) that you can build your specifications around. Contrast this to the example you give where Arrange, Act and Assert are combined into one line of code.

2
  • Sorry if this seems too low level, but I still have the same question I had in my follow-up question. How are you defining "system behavior"? Is it behavior provided to an external client (e.g. a user, another system)
    – Aeden
    Jun 5, 2011 at 17:06
  • @Aeden:He means it represents an executable and human readable documentation which describes the way your [part of] software (system) behaves.
    – Mohsen
    Jul 4, 2017 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.