Sitecore UnitTest with FakeDb
When you are working on the CMS solution, the solution design and architecture can be very different, that caused writing and maintaining the uint tests be even more difficult than bespoke solution.
A typical example of this is at some point your code calls the Sitecore API, how do you ensure your code is working when the code has related to external dependencies that you canβt remove?
Thanks for Sitecore FakeDb, it makes that happen and a lot simpler to write the unit tests on this CMS plateform. In the following sections, I will assume you are a Sitecore developer with passion of writing the unit tests.
Dependencies
In order to use FakeDb for the unit tests, you need the following dlls within your Tests project
- Sitecore.FakeDb β You can install this via the nuget package
- Lucene.Net
- Sitecore.Analytics
- Sitecore.Kernel
- Sitecore.Logging
- Sitecore.Nexus
NOTES: All above Sitecore related packages can be either reference from dll or via Sitecore nuget server.
Lastly, you also need to copy your Sitecore license.xml file into the root of your Test project.
NOTE: When you install the Sitecore.FakeDb package, it will automatically update the app.config file by including the license file location (see screenshot below
Sample Test (MSTest)
NCrunch Configuration
In order to run unit tests with NCrunch, in the NCrunch Configuration window, select the tests project and configure the following settings:
References
NCrunch
https://github.com/sergeyshushlyapin/Sitecore.FakeDb/wiki/Configuration
AutoFixture with Sitecore.FakeDb
https://github.com/sergeyshushlyapin/Sitecore.FakeDb/wiki/AutoFixture-Samples
Happy Coding! π
Comments powered by Disqus.