this was working fine with basic testing, however it's gone to pot the moment we've got a class/interface that's using the 'UmbracoHelper' which of course needs the good old 'UmbracoContext'.
on the advice of many blog posts we've used this to get the context:
Test method Site.Tests.UmbracoTests.TestMethod1 threw exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: applicationContext
at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache..ctor(ApplicationContext applicationContext)
at Umbraco.Tests.TestHelpers.BaseDatabaseFactoryTest.GetUmbracoContext(String url, Int32 templateId, RouteData routeData, Boolean setSingleton)
at Umbraco.Tests.TestHelpers.BaseRoutingTest.GetRoutingContext(String url, Int32 templateId, RouteData routeData, Boolean setUmbracoContextCurrent)
at Umbraco.Tests.TestHelpers.BaseRoutingTest.GetRoutingContext(String url, RouteData routeData)
at Site.Tests.UmbracoTests.GetUmbracoContext() in UmbracoTests.cs: line 28
at Site.Tests.UmbracoTests.TestMethod1() in UmbracoTests.cs: line 55
which has left us a bit stumped!
has anyone hit this before or has a better solution to creating the 'UmbracoContext'?
did a lot of parallel stepping through code in visual studio with the umbraco test project on one side and ours on the other trying to figure out what was going wrong. line 356 in 'Umbraco-CMS-dev-v7\src\Umbraco.Tests\TestHelpers\BaseDatabaseFactoryTest.cs' was the key: in the umbraco project 'ApplicationContext' was populated, in ours it wasn't.
we traced that back to the set up and noticed it was using nunit in the Umbraco.Tests.dll...
in my project i was using the ms test declarations ([TestClass] and [TestMethod]) so i changed them to [TestFixture] and [Test] and guess what?
one populated UmbracoContext - happy days!
now all i need to do is get my ms fakes to play nicely so i can shim out the 'GetPropertyValue' extension methods and i'm getting somewhere.
unit testing: creating an 'UmbracoContext ' throws an exception?!
hey out there,
we're in the process of getting a project unit tested... we're getting there, the learning curve is steep but it's beginning to make a bit of sense!
what we've done so far:
this was working fine with basic testing, however it's gone to pot the moment we've got a class/interface that's using the 'UmbracoHelper' which of course needs the good old 'UmbracoContext'.
on the advice of many blog posts we've used this to get the context:
but when we run our tests, we get this:
which has left us a bit stumped!
has anyone hit this before or has a better solution to creating the 'UmbracoContext'?
cheers,
jake
found it!
did a lot of parallel stepping through code in visual studio with the umbraco test project on one side and ours on the other trying to figure out what was going wrong. line 356 in 'Umbraco-CMS-dev-v7\src\Umbraco.Tests\TestHelpers\BaseDatabaseFactoryTest.cs' was the key: in the umbraco project 'ApplicationContext' was populated, in ours it wasn't.
we traced that back to the set up and noticed it was using nunit in the Umbraco.Tests.dll...
in my project i was using the ms test declarations ([TestClass] and [TestMethod]) so i changed them to [TestFixture] and [Test] and guess what?
one populated UmbracoContext - happy days!
now all i need to do is get my ms fakes to play nicely so i can shim out the 'GetPropertyValue' extension methods and i'm getting somewhere.
happy (almost) days ;)
Hi,
I have exactly the same problem but moving to NUnit did not resolve it. Please see my detailed question at https://our.umbraco.org/forum/using-umbraco-and-getting-started//91668-umbraco-unit-testing-problems-due-to-null-applicationcontext-umbraco-context
Thanks
Terry Clancy
ClanceZ
All,
See resolution at
https://our.umbraco.org/forum/using-umbraco-and-getting-started//91668-umbraco-unit-testing-problems-due-to-null-applicationcontext-umbraco-context
Terry Clancy ClanceZ
is working on a reply...