5 votes

Quixote tests with Razor

Using Rob Conerys testing micro framework for WebMatrix in Umbraco

Note that this is a very early version, I have been using it very briefly in production and found it both helpful and fun - so I liked to share it already. The Quixote.cs is expected to change quite a lot especially in the beginning, I intend to update this package as Quixote is updated.

https://github.com/robconery/Quixote

Add this package and you can write BDD like tests in Razor code; for example to check that a page has the right title, the right number of links, contains no "error" text. I also added a sample to look for all pages for "error" texts.

Install the package and run the test by opening mysite.com/quixote

Edit the tests in the razor scripts in the /tests folder

Test examples https://github.com/robconery/Quixote/blob/master/Examples/Basics.cshtml

Tip: Run the tests manually or scheduled with the help of the Scheduler package - with that you can get daily test reports to your email inbox (before your client calls you and asks whats wrong).

Here's how some sample tests could like:

 @TheFollowing.Describes("Testing root page /:")
    @It.Should("have the right title", () => {
        return Runner.Get("~/").Title.ShouldEqual("Starterkit start page");
    })

    @It.Should("have correct number of links", () => {
        return Runner.Get("~/").Links.ShouldHaveACountOf(23);
    })

    @It.Should("contain no error", () => {
        return Runner.Get("~/").Body.ShouldNotContain("Error");
    })

    @It.Should("contain 'Runway' somewhere on page", () => {
        return Runner.Get("~/").Body.ShouldContain("Runway");
    })

In version 0.2 (which is also experimental) : I added w3c-validations:

    @It.Should("validate", () => {
          return "mysite.com".UrlShouldValidate();
    })

I also added a simplified default test script for any dynamic node. For now it tests for error texts and validates. See screen shot 2 "Default test ..." Use it like this:

  @RenderPage("~/macroscripts/tests/pagetest.cshtml",Model.AncestorOrSelf())

Look at the first screen shot below. It tells us that the title of the startpage is wrong, otherwise everything is correct. If some of the child pages should have a Xslt or Razor error we would get a red row for that page.

In the second screen shot we see version 0.2 running with validations. We see that no page validates - which is no surprise as the site runs on localhost. When run on a live site though, it works as expected. It's using the online w3c xhtml validator and looks for the success string. I don't know if it's recommended to use the validator in an automated way like this?

 

Screenshots

Package owner

Jonas Eriksson

Jonas Eriksson

Jonas has 1825 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
Version 8.18.x (untested)

You must login before you can report on package compatibility.

Previously reported to work on versions:

Package Information

  • Package owner: Jonas Eriksson
  • Created: 28/04/2011
  • Current version 0.2
  • License MIT
  • Downloads on Our: 1.2K