0

I'm using sharepoint 2013 and trying to unit testing for my methods. Had issues in methods having SPContext and HTTPContext but can resolve that with help of article here

Now i want to test the methods which are using SPUser, in order to achieve this i want to mock the user with my own data for example. I want the SPUser.LoginName as "test" and SPUser.Email as [email protected].

My aim is to to mock the current user in unit testing i.e, web.CurrentUser

Can anyone help on this?.

Thanks in advance..

1
  • Are you using any framework for mocking?
    – Aanchal
    Jun 19, 2014 at 6:30

1 Answer 1

1

There is no direct way to Mock SPUser object. You can use various tools to perform unit testing for Sharepoint:

http://msdn.microsoft.com/en-in/library/ff650441.aspx

http://blog.typemock.com/2008/09/16/testing-sharepoint-now-easier-with-the-new-api

http://www.telerik.com/forums/mocking-spuser

1
  • Thanks Aanchal. I tried all these already, but i'm not able to mock SPWeb.CurrentUser. instead everytime i'm gettin the user who has logged in the server, in my case its "Administrator". Jun 19, 2014 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.