This post has been migrated from www.experimentsincode.com, we apologise if some of the images or content is missing

The post describes the steps you will need to take to get Sitecore 6.5 running in the NUnit GUI. This will allow you to run unit tests in the NUnit GUI that pull data from Sitecore. I will be using the test assembly from the Glass.Sitecore.Mapper project as the example. First we have our project with the test assembly:
In the test assembly create an App.Config:
Copy the contents of the App_Config directory in your website to the App_Config directory in your test assembly:
Notice that in my App_Config directory I also have a Sitecore.Config file, this contains the contents of the /configuration/sitecore node that normally lives in the Web.Config. I like to separate out the Sitecore section from the main web.config because it is such a large piece of config. Open the  App.Config file in your test assembly and add the following configuration sections to /configuration/configsections:
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Sitecore.Logging" />
    <section name="sitecore" type="Sitecore.Configuration.ConfigReader, Sitecore.Kernel" />
Beneath the /configuration element add:
   <sitecore configSource="App_Config\Sitecore.config" />
   <log4net />
Your App.Config should look something like this: Now open the file /App_Config/Sitecore.config, this should contain the main Sitecore config, you will now need to go through the config to change all paths to the files that are included, the changes are detailed below:
Line Original New
7 <sc.include file="/App_Config/Prototypes.config" /> <sc.include file=".\App_Config\Prototypes.config" />
665 <sc.include file="/App_Config/Prefetch/Common.config" /> <sc.include file="/App_Config/Prefetch/Core.config" /> <sc.include file=".\App_Config\Prefetch\Common.config" /> <sc.include file=".\App_Config\Prefetch\Core.config" />
703 <sc.include file="/App_Config/Prefetch/Common.config" /> <sc.include file="/App_Config/Prefetch/Master.config" /> <sc.include file=".\App_Config\Prefetch\Common.config" /> <sc.include file=".\App_Config\Prefetch\Master.config" />
748 <sc.include file="/App_Config/Prefetch/Common.config" /> <sc.include file="/App_Config/Prefetch/Web.config" /> <sc.include file=".\App_Config\Prefetch\Common.config" /> <sc.include file=".\App_Config\Prefetch\Web.config" />
997 <add name="domains" type="Sitecore.Configuration.XmlConfigStore, Sitecore.Kernel" factoryMethod="LoadFromFile" arg0="/App_Config/Security/Domains.config" /> <add name="globalRoles" type="Sitecore.Configuration.XmlConfigStore, Sitecore.Kernel" factoryMethod="LoadFromFile" arg0="/App_Config/Security/GlobalRoles.config" /> <add name="domains" type="Sitecore.Configuration.XmlConfigStore, Sitecore.Kernel" factoryMethod="LoadFromFile" arg0=".\App_Config\Security\Domains.config" /> <add name="globalRoles" type="Sitecore.Configuration.XmlConfigStore, Sitecore.Kernel" factoryMethod="LoadFromFile" arg0=".\App_Config\Security\GlobalRoles.config" />
1083 <sc.include file="/App_Config/FieldTypes.config" /> <sc.include file=".\App_Config\FieldTypes.config" />
1517 <sc.include file="/App_Config/XamlSharp.config" /> <sc.include file=".\App_Config\XamlSharp.config" />
1521 <sc.include file="/App_Config/LanguageDefinitions.config" /> <sc.include file=".\App_Config\LanguageDefinitions.config" />
1808 <sc.include file="/App_Config/MimeTypes.config" /> <sc.include file=".\App_Config\MimeTypes.config" />
1834 <sc.include file="/App_Config/Commands.config" /> <sc.include file=".\App_Config\Commands.config" />
1838 <sc.include file="/App_Config/Icons.config" /> <sc.include file=".\App_Config\Icons.config" />
1842 <sc.include file="/App_Config/Portraits.config" /> <sc.include file=".\App_Config\Portraits.config" />
You will also need to change the path to your license file to the full path:
    <setting name="LicenseFile" value="D:\projects\Glass\Sitecore\Data\license.xml" />
Finally for every file beneath the App_Config in your test assembly you need to ensure that it is copied on build:
Your test assembly will need to reference the following Sitecore assemblies:
  • Sitecore.Kernal.dll
  • Sitecore.Logging.dll
  • Sitecore.Nexus.dll
Finally to test that you have configured the test assembly correctly you can create a simple test to pull some data from Sitecore:
    [TestFixture]
    public class SitecoreConnectionFixture
    {
        [Test]
        public void ConnectionTest_ConnectsToSitecoreDatabase_RetrievesRootItem()
        {
            Database db = global::Sitecore.Configuration.Factory.GetDatabase("master");
            Item item = db.GetItem("/sitecore");
            Assert.IsNotNull(item);
            Assert.AreEqual("sitecore", item.Name.ToLower());

        }
    }