With QUnit I can explicitly expect that a specific number of assertions will be run in my test (heck, by default at least 1 assertion is expected anyways, or the test fails).
Is there any way to do something similar with NUnit? (Heck, by default tests without assertions even pass...).
To clarify, here's an example / repro. Suppose I'm test-driving this code:
public class Util
{
public static void MyMethod(Action someAction)
{
// We're TDD'ing, and we are *just about* to write:
//someAction();
}
}
then before I write that someAction(); call I want to write a test. Here's the test I want to write:
[Test]
public void MyMethod_WhenGivenAction_ShouldCallAction()
{
Assert.Expect(1); // Pseudo code, but this doesn't work.
Util.MyMethod(() => Assert.That(true));
}
Of course I can workaround with this:
[Test]
public void MyMethod_WhenGivenAction_ShouldCallAction()
{
bool wasCalled = false;
Util.MyMethod(() => wasCalled = true);
Assert.That(wasCalled);
}
And I guess I could even write my own Extension method on Assert to do this in a single line, but I was wondering if there's an idiomatic / built in way to "expect N assertions" with NUnit?
Aucun commentaire:
Enregistrer un commentaire