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..

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

1 Answer 1


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




  • 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". Commented Jun 19, 2014 at 12:43

Your Answer

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

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