Aeden
Aeden

Reputation: 101

Is it possible to create data driven tests with MSpec?

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);
  }
}

Upvotes: 10

Views: 1059

Answers (1)

Alexander Groß
Alexander Groß

Reputation: 10458

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.

Upvotes: 4

Related Questions