Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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')

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?

share|improve this question

closed as off-topic by gnat, GlenH7, MichaelT, Bart van Ingen Schenau, Dan Pichelman Jun 4 '14 at 12:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – gnat, GlenH7, MichaelT, Bart van Ingen Schenau, Dan Pichelman
If this question can be reworded to fit the rules in the help center, please edit the question.

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
+1 for making the effort to test your code. – semaj Jan 27 '12 at 16:35

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer
+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

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.

share|improve this answer
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

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