Home > C#, Sitecore 6, Sitecore Fakes, Unit Testing > Getting started with Sitecore Fakes

Getting started with Sitecore Fakes

in this post I will give a simple guide that can get you started on using Sitecore Fakes. So you can start doing unit testing with Sitecore.  You can use Sitecore fakes with any testing framework for example Nunit Xunit o any like those.

1. First  you should go and download the the code from github :

https://github.com/istern/Sitecore-Fakes

2.  Once you have downloaded the code start it up in Visual Studio, and fix the missing reference for the Sitecore.Kernel.dll see image below, and then build the project. If the test project fails you can, if you like, fix the missing references for Sitecore.Kernel and Sitecore.Nexus all other references can be updated through nuget. But it is not required to get Sitecore.Fakes to work.

geetingstartedsf

3. Now open the solution that holds the code you want to test and add a new “class library” to the solution. To the newly created project  you will need to add an app.config file and a references off course to the Sitecore .Fakes.dll you just build in step 2. The App.config filles is ONLY REQUIRED if you need to access anything else but the the “Item.Fields” for example the database child colletion and so on. The content for the app.config you can copy in from test project that Sitecore Fakes comes with and has on Github, but as a service i will give it here.

</pre>
<?xml version="1.0"?>
<configuration>
 <configSections>
 <section name="sitecore" type="Sitecore.Configuration.ConfigReader, Sitecore.Kernel"/>
 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Sitecore.Logging"/>
 </configSections>
 <sitecore database="SqlServer">
 <itemManager defaultProvider="default">
 <providers>
 <clear/>
 <add name="default" type="Sitecore.Fakes.FakeItemProvider,Sitecore.Fakes"/>
 </providers>
 </itemManager>
 <databases>
 <database id="web" singleInstance="true" type="Sitecore.Fakes.FakeDatabase, Sitecore.Fakes">
 <param desc="name">$(id)</param>
 </database>
 </databases>
 <mediaLibrary>
 <mediaProvider type="Sitecore.Fakes.FakeMediaProvider, Sitecore.Fakes"/>
 </mediaLibrary>
 <settings>
 <setting name="LicenseFile" value="C:\license.xml"/>
 </settings>
 </sitecore>
 <log4net>
 </log4net>
</configuration>
<pre>

4. Next add a reference to Sitecore kernel and Sitecore Nexus in the newly created class.
6.  Write your first test and see is Fail …. or Pass

In the future hopefully Sitecore Fakes will be available through nuget so you can skip a few of the steps above. more details aboudt Sitecore Fakes ca be found in my earlier posts here and here

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: