I'm using some .NET UnitTests working with the object complex_object.
Now, I'd like to modify one of his atteribute in order to test the behaviour of one method and, after finishing the test, restore it to the original value. Now I'm doing like this:
[TestMethod]
public void FooTest()
{
int oldVar = complex_object.attribute;
complex_object.attribute = -1;
var result = method_yo_test(complex_object);
complex_object.attribute = oldVar;
}
But it is a very ugly method, I'll to use something like (RSPEC style):
[TestMethod]
public void FooTest()
{
allow_any_instance_of(complex_object).to receive(attribute).and_return(-1)
var result = method_yo_test(complex_object);
}
Is there a way to mock a method like this?
Aucun commentaire:
Enregistrer un commentaire