Note that there are some explanatory texts on larger screens.

plurals
  1. POstub and mock implementation
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/463707/what-are-the-differences-between-mocks-and-stubs-on-rhino-mocks">What are the differences between mocks and stubs on Rhino Mocks?</a> </p> </blockquote> <p>I am using mocks of unit testing..But I can't get the difference between mock and stub in the implementation code.. the mock implementation code is:-</p> <pre><code>[TestFixture] public class MockUser { [Test] public void SaveValidUserFileNameUsingMock() { UserMock um = new UserMock(); um.uName = ""; um.fName = "sfs.jpg"; um.ContentType = "image/jpg"; IUser usr = um; Assert.AreEqual("E:/image/kawade.jpg", usr.Save(um)); } } public class UserMock : IUser { public string uName; public string fName; public string ContentType; public string Save(IUser u) { if (uName == "" || fName == "") { throw new ArgumentException("missing field name"); } if (ContentType.Contains("image")) { string ext = Path.GetExtension(fName); return (string.Format("E:/image/{0}", this.uName + ext)); } return "invalid"; } } public interface IUser { string Save(IUser u); } </code></pre> <p>and the class to test is:-</p> <pre><code>public class User { public string uName; public string fName; //private IUser usr; public void Save(FileUpload fu, User usr) { if (uName == null || fName == null) { throw new ArgumentException("missing field name"); } if (fu.PostedFile.ContentType.Contains("image")) { string ext = Path.GetExtension(fName); fu.SaveAs(string.Format("E:/image{0}", this.fName + ext)); } } </code></pre> <p>and the same class is being used for stub testing. the stub testing code is:-</p> <pre><code>[TestFixture] public class UserTest { [Test] public void SaveUserValidFile() { UserStub su = new UserStub(); su.uName = "kawade"; su.fileName = "sfgs.png"; su.Contenttype = "image/x-png"; su.pName = "sdskjh"; IUser target = su; } } internal class UserStub : IUser { public string uName; public string pName; public string Contenttype; public string fileName; public string Save(IUser u) { if (uName == null || pName == null) { throw new ArgumentException("user_name or pic_name is required"); } if (Contenttype.Contains("image")) { string ext = Path.GetExtension(fileName); //return string.Format("C:/test/{0}", this.uName + ext); Assert.AreEqual("C:/Test/kawade.png", target.Save(su)); } return ""; } } public interface IUser { string Save(IUser u); } </code></pre> <p>please someone let me know the difference between stub and mock and it's implementation in above code..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload