-
Notifications
You must be signed in to change notification settings - Fork 0
/
2005-03-07-black-box-testing-of-commandline-tools-with-tt-expect-tt.html
8 lines (7 loc) · 2.05 KB
/
2005-03-07-black-box-testing-of-commandline-tools-with-tt-expect-tt.html
1
2
3
4
5
6
7
8
---
layout: post
title: "Black Box Testing of Commandline Tools with <tt>expect</tt>"
permalink: black-box-testing-of-commandline-tools-with-tt-expect-tt.html
---
<p>Automated <a href="http://www.faqs.org/faqs/software-eng/testing-faq/section-13.html">black box testing</a> of commandline tools tends to be (but should not be) a bit of a black art. There is a tendency among Java developers to ignore otherwise useful tools and ideas that aren't prepackaged for either Ant or JUnit, and even if I'm working with commandline tools implemented in Java, my preference is for <a href="http://expect.nist.gov/"><tt>expect</tt></a>, a tool specifically for automating interactive <em>commandline</em> applications. The language is based on <a href="http://tcl.sourceforge.net/">Tcl</a>, which isn't too unreasonable to pick up given a few examples, and <tt>expect</tt> comes with most *nixes (including Mac OS). (It is also available for Windows.) The point of <tt>expect</tt> is that you can use it to spawn one or more processes, send them text, and tell the tool what to <em>expect</em> (Get it...?) in the way of output. Conveniences like expected response timeouts, regular expressions, and basic control flow (via Tcl) are all natively available in <tt>expect</tt>.</p>
<p>There are plenty of more or less instructive <a href="http://expect.nist.gov/example/">examples</a> available, but for a concrete use case, an <tt>expect</tt> script could download and unpack a fresh Tomcat, drop and refresh a database, launch the Tomcat, deploy a web application by copying a WAR into place, and watch the Tomcat logs to ensure that nothing unexpected happens while the same script runs a test client against the web application from another machine. It's also reasonable to write <tt>expect</tt> scripts that simulate the examples provided in user documentation as part of an integration test suite. (Essentially, <tt>expect</tt> can do whatever you might normally do with a bunch of shell windows open on your desktop, including logging into other servers and interacting with the remote shell.)</p>