8

I work at a web design shop. Our workflow is divided into two parts: frontend programmers make static html and css templates of the site design, then backend programmers tie the templates into a CMS.

We have a set of common functionality for our sites, and I'm wondering if there's a unit testing framework we can use to test for this functionality.

For example, one of our common functionality guidelines states that all links to a pdf must open in a new window. I would like to write a unit test that goes something like this

if(a.class = 'pdf_link')
  assert(target='_blank)

Wikipedia's list of unit testing frameworks doesn't seem to have anything that encompasses this relatively simple functionality (checking strings against a template), and I'm leaning towards writing a bunch of bash scripts and tying them into our CI server.

But is there an better way to do this?

  • I don't think you need an HTML unit testing framework. You can parse the HTML and then run unit testing against the objects just like normal. What programming language are you using? – The Muffin Man Jan 27 '12 at 5:29
2

You need to test the DOM, not the text output. I don't know what language you are developing in, but in PHP there is PHPUnit, which can do DOM checks. Look into using assertSelectEquals. My battery is about to die and I don't have my cord, or I would give you more.

  • Yeah, but I want to check static HTML files. I'm developing in HTML – CamelBlues Jan 30 '12 at 20:03
  • @CamelBlues You misunderstand: you can use any programming language to test static HTML. PHPUnit even supports Selenium. – Levi Morrison Jan 30 '12 at 20:14
  • Five years later, I've realized this is the correct answer. – CamelBlues Sep 29 '17 at 23:00
6

I am wondering if perhaps something like Selenium would do the trick? Its a testing mechanism that is run on behavioural driven development. It can run through UI actions so that you confirm if they are correct or not. Note that I haven't used it a lot but when I did it seemed really useful.

Selenium Homepage

  • 1
    +1: The question may say "HTML Markup" but all of the examples are simple web functionality. – S.Lott Jan 27 '12 at 10:46
  • This actually looks like the best solution for my needs (although the complexity of Selenium itself does look a little intimidating) – CamelBlues Jan 30 '12 at 20:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.