All my viewmodels fail because UmbracoContext is null and cannot create a UmbracoHelpr without it. So I was wondering: is there any way to mock the UmbracoContext or what alternatives are there to setup unit tests for Umbraco?
I have read some pretty old posts on the Umbraco forum but the best I've found was to grab a file/class from the source code (because it has some internal methods that are needed to create the UmbracoContext), which seems highly unnecessary (or at least it should be, IMO).
I have the same problem, what unit testing framework are you using? I use Rhino Mocks and it was OK stubbing a UmbracoHelper but I experienced real difficulties when I came across extension methods. I hear that TypeMock or there is a Ms solution as part of Visual Studio Premium, both are paid for options.
Just thinking about it another solution may be to use the new Model Builder (or this for older Umbraco versions https://github.com/zpqrtbnk/Zbu.ModelsBuilder) to encapsulate all the UmbracoHelper calls in auto generated code and then mock these models when testing your viewmodels.
Unit Testing and mocking UmbracoHelper
Hey guys.
How do you guys Unit Test your Umbraco Solutions?
All my viewmodels fail because UmbracoContext is null and cannot create a UmbracoHelpr without it. So I was wondering: is there any way to mock the UmbracoContext or what alternatives are there to setup unit tests for Umbraco?
I have read some pretty old posts on the Umbraco forum but the best I've found was to grab a file/class from the source code (because it has some internal methods that are needed to create the UmbracoContext), which seems highly unnecessary (or at least it should be, IMO).
I have the same problem, what unit testing framework are you using? I use Rhino Mocks and it was OK stubbing a UmbracoHelper but I experienced real difficulties when I came across extension methods. I hear that TypeMock or there is a Ms solution as part of Visual Studio Premium, both are paid for options.
Just thinking about it another solution may be to use the new Model Builder (or this for older Umbraco versions https://github.com/zpqrtbnk/Zbu.ModelsBuilder) to encapsulate all the UmbracoHelper calls in auto generated code and then mock these models when testing your viewmodels.
Let me know what you think...
Hey Dennis, I released a NuGet package to do exactly this. You can find it at https://www.nuget.org/packages/GDev.Umbraco.Testing/ and also some examples on the github repo https://github.com/garydevenay/Umbraco-Context-Mock
Hope this is helpful!
is working on a reply...