tag:blogger.com,1999:blog-5589343447323430312.post3608562323471456135..comments2024-03-10T04:27:33.846-04:00Comments on Explorations: Sitecore NUnit Testing SimplifiedDan Solovayhttp://www.blogger.com/profile/02204911460102862983noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-5589343447323430312.post-83523266704768890102013-11-19T06:35:12.497-05:002013-11-19T06:35:12.497-05:00OK, I found the problem. For me it was an empty co...OK, I found the problem. For me it was an empty config transformation file which got somehow copied to the Include folder of the website and therefore also to the test project. After I removed it from the include folder of the Test project, the test went green.<br />It is interesting that the files are also in the Debug (/App_Config/Debug) folder but this doesn't appear to have an impact on the debug process.Anonymoushttps://www.blogger.com/profile/03875429787613690931noreply@blogger.comtag:blogger.com,1999:blog-5589343447323430312.post-28415795013470091102013-11-19T04:36:19.332-05:002013-11-19T04:36:19.332-05:00Sorry, I meant to writethat it is NUnit. Somehow g...Sorry, I meant to writethat it is NUnit. Somehow got lost somewhere. ;)Anonymoushttps://www.blogger.com/profile/03875429787613690931noreply@blogger.comtag:blogger.com,1999:blog-5589343447323430312.post-7940129537106579372013-11-18T15:31:26.336-05:002013-11-18T15:31:26.336-05:00@Kai Are you using NUnit or MSTEST?@Kai Are you using NUnit or MSTEST?Dan Solovayhttps://www.blogger.com/profile/02204911460102862983noreply@blogger.comtag:blogger.com,1999:blog-5589343447323430312.post-54473538652002716412013-11-18T09:01:11.622-05:002013-11-18T09:01:11.622-05:00I have the same problem. I am running the tests in...I have the same problem. I am running the tests inside Visual Studio 2012 with Resharper. When I use debug the test goes through. If I run it I am getting the above error when setting the IsUnitTesting to true.Anonymoushttps://www.blogger.com/profile/03875429787613690931noreply@blogger.comtag:blogger.com,1999:blog-5589343447323430312.post-46651103077582075232013-08-09T00:42:45.919-04:002013-08-09T00:42:45.919-04:00Are you using MSTEST rather than NUnit? MSTEST run...Are you using MSTEST rather than NUnit? MSTEST runs outside of the output directory, either in the TestResults folder or in the %temp% location, so it won't have access to the files copied to the output directory. You can prove this out by including this line in your tests:<br />Console.WriteLine("Working directory: " + System.IO.Directory.GetCurrentDirectory());<br /><br />This behavior seems to have changed with Visual Studio 2012, which appears to run tests from the output directory.<br /><br />You should be able to resolve by replacing [TestClass] with [TestFixture], and [TestCase] with [Test], and adding an assembly reference to NUnit.framework. You would then have to use a different test runner, such as the NUnit Gui.<br /><br />If you must stick with MSTest and cannot move to Visual Studio 2012, you may want to look into the [DeploymentItem] attribute to move the resources over that you need. See this on Stack Overflow: http://stackoverflow.com/questions/3738819/do-mstest-deployment-items-only-work-when-present-in-the-project-test-settings-f<br /><br />Good luck, and thanks for the feedback!<br />DanDan Solovayhttps://www.blogger.com/profile/02204911460102862983noreply@blogger.comtag:blogger.com,1999:blog-5589343447323430312.post-77879814955967178252013-08-07T18:05:23.091-04:002013-08-07T18:05:23.091-04:00Great post Dan! It was very helpful. I followed th...Great post Dan! It was very helpful. I followed these steps and was able to solve the auto include issue. However, I'm running into an unusual issue. <br /><br />I created a test project with two unit tests. <br />I can successfully run the unit tests when I run them in the debugger (Test->Debug->All Tests option in the Visual Studio). When I run these tests in the Test Explorer, they fail to run and the following exception is thrown:<br />------------------------------------------------<br />Result Message: <br />SetUp : System.TypeInitializationException : The type initializer for 'Sitecore.Diagnostics.LoggerFactory' threw an exception.<br /> ----> System.NullReferenceException : Object reference not set to an instance of an object.<br />Result StackTrace: <br />at <br />------------------------------------------------<br /><br />This exception is thrown while executing the following in the test method.<br /><br />var db = Sitecore.Configuration.Factory.GetDatabase("master");<br /><br />Any ideas why would the tests run fine in the debugger but not in the test explorer? <br /><br />Thanks,<br />AndyAnonymousnoreply@blogger.com