Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create data driven tests with MSpec?

Tags:

tdd

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);
  }
}
like image 439
Aeden Avatar asked May 25 '11 08:05

Aeden


1 Answers

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.

like image 91
Alexander Groß Avatar answered Sep 28 '22 07:09

Alexander Groß