Wednesday, October 14, 2009

Unit testing SharePoint WSS 3.0 x64 bit

Problem
trying to MS unit test code on x64 bit OS with x64 bit WSS 3.0 installed

[TestMethod]
public void TestMethod1()
{
using (SPSite sp = new SPSite("http://localhost:13000/"))
{
Console.WriteLine(
"Site valid");
}
}

Error Message
Test method TestProject1.UnitTest1.TestMethod1 threw exception:

System.IO.FileNotFoundException: The Web application at http://localhost:13000/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add
a new request URL mapping to the intended application..

Solution
http://community.bamboosolutions.com/forums/t/8179.aspx
download nunit (only 32 bit). Nunit will automatically choose which JIT compiler to use to test the code.

Additional Stuff
Code modification to have both nunit and MS test running together
http://www.martinwilley.com/net/code/nunitmstest.html

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestContext = System.Object;
#endif

2 comments: