I'm new to TDD, but I'm not sure why should I test an interface?
Does the code below make sense??
public interface IInterface
{
int Value { get; }
}
[TestMethod]
public void Test_iinterface_value()
{
var iinterface = mockery.NewMock<IInterface>();
Expect.Once.On(iinterface).GetProperty("Value").Will(Return.Value(10));
Assert.AreEqual(iinterface.Value, 10, "Doh!");
}
Unless I am mistaken it looks like you are creating a mock object that returns given value when asked for it. And then you ask for the value & you get it (surprise). I’d say it does not make sense to write such tests, unless you are testing the mocking framework itself or you expect the compiler to play some dirty tricks on you.
This is known as the Mockery TDD anti-pattern.
However, you may want to write a set of tests that applies to all implementers of a given interface to ensure that the contracts is being properly implemented. As an example, this is what Grensesnitt does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With