lundi 19 septembre 2016

Avoid running function within Unit Test (NUnit)

Say I have a class:

public class SomeClass {

   public Model _model;

   public SomeClass() {
     _model = new Model(); 
   }

   public void Foo() {
     _model.DoSomethingHeavy();
   }

}

And a Test:

[TestFixture]
public class SomeClassTest {

  [Test]
  public void TestFooCalledSomethingHeavy() {
    SomeClass someClass = NSubstitute.Substitute.For<SomeClass>();  
    someClass.Foo();        
    someClass._model.Received().DoSomethingHeavy();
  }
}

I'm trying to test that someClass.Foo(); called _model.DoSomethingHeavy() but I don't actually want DoSomethingHeavy to run. How would I do that? Or is this the wrong approach?

Aucun commentaire:

Enregistrer un commentaire