c# - What is the simplest unit test to implement for asserting a particular method is called? -
I have a class and I want to implement a unit test in a public way to indicate a specific test I am
To make it simple, let's take a square and unit test below.
What should I do or should do (such as an interface etc) so that I can say "MacNoise Methi calls Bark method" I can use Rhinomox if needed This is what you are interested in, output . Test Output If the exam is inside the classroom under the test, then this is the implementation details. Where you want to test interaction , if your class has a collaborator, and you want to check With it, the hierarchy of your class (if it is indeed an indication) can use some work you still go to create a
Public category animal {public string AnimalType {get; Set;} public string bark () {if (AnimalType == "dog") {return "Hof! Hof! Hof!"; } Return string Empty; } Public string mechanisms () {if (AnimalType == "dog") {return bark (); } Return string Empty; }} [TestMethod] Public Zero Mknowize_with AnimalTypeDog_CallsBarkMethod () {var dog = New animal () {AnimalType = "dog"}; Dog.MakeNoise (); // How can I test the macanois method, called berkmouth? }
Var = "Hoff! Hoff! Hoff!"; Var real = dog McNow (); Extraordinary (Actual, expected);
Animal to be separated from the collaborator (probably
Bar ). Again You can choose to use the
bar to make a
animal (and, of course, you will have appropriate tests Real
Bar ) If this is close to your actual question, please update it.
animal should not be a method which is only relevant to the dog You should create a
dog , which should not be sorted in class (class, math, whatever)
Animal , make it appropriately by
MakeNoise override the method.
class Animal {public virtual string mechanis () {whatever the return; }} Class dog: animal {public override string mechanis ()} "return" Hof! Hof! Hof! ";}} // animal dog = new dog (); var noise = dog.channelize ();
animal abstract
Comments
Post a Comment