Try our conversational search powered by Generative AI!

crli
Sep 23, 2010
  4337
(0 votes)

Testing templates without creating a page using TemplateMock

Sometimes it’s useful to test your code before committing it. When possible unit tests make for a nice way to do this. Template code, however, is not always the most easy to test as a unit. This is when a UI testing framework such as Selenium can come in handy. Unfortunately creating the pages to test can be a bit cumbersome and this is where TemplateMock helps out.

Usage

TemplateMock allows you to access a page type without creating it in edit mode from a known URL. After adding templateMock to your site you can render a standard page using an alternative url:

image

/TemplateMock.ashx?scenario=[Public]+Standard+page

Configuration

When navigating to TemplateMock without query parameters you can choose which template to execute:

image

Optionally you can add query parameters to configure it:

randomize (true/false): Wheter the content on the page is deterministic (doesn’t change every time)

numberOfChildren (0-n): How many children this page appears to have

For example “/TemplateMock.ashx?scenario=[Public]+Standard+page&randomize=false&numberOfChildren=100” will render a standard page with 100 child pages without randomizing it’s content.

It’s also possible to tweak other aspects from code. This is left as an excercise to the reader.

Download & installation

Be aware that TemplateMock broadcasts unsupported pirate signals to hack into the CMS core and should never be used in production.

To install it just unzip in your site’s root directory and navigate to TemplateMock.ashx.

Sep 23, 2010

Comments

Sep 23, 2010 06:36 PM

This looks like a very interesting concept. We run EPiServer from the command line for unit testing so this looks like a useful addition to the testing tools out there!

Joel Abrahamsson
Joel Abrahamsson Sep 24, 2010 12:57 PM

Brilliant!

Any chance you can upload the source code as well? Preferably to GitHub or some other place where it's easily forkable :)

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024