Posted by: Brian | July 26, 2010

Rational Functional Tester: File Compare

The Rational Tester was visiting a client who had recently purchased Rational Functional Tester. During the meeting, a question came up as to what would be the best approach to comparing two files in a Rational Functional Tester script. It was fun to get back to my geeky roots, and with Rational Functional Tester being built upon Java, we had lots of easy options.

For this particular situation, all that was required was a simple “Yes / No” answer. Either the files were the same or they were not. In this situation, probably the simplest approach is to leverage the apache commons i/o libraries.   In this library, you’ll find one line file compare function called contentEquals.

To use this library from Rational Functional Tester, download the library (currently the latest version is “commons-io-1.4-bin.zip”, expand the zip and copy the “commons-io-1.4.jar” to the RFT customization directory which by default is C:\Documents and Settings\All Users\Application Data\IBM\RFT\customization.  This process, by the way, is documented in the Rational Functional Tester Help.

From there, you’ll need to add two import statements.  First you need java.io to gain access to the File object type that is required by the contentEquals function.  Of course, you’ll also need the contentEquals function which is in the org.apache.commons.io.FileUtils package.

With the imports in place, create two file objects, one for each file, and then use a vpManual to compare the results of the comparison.  Here is a screenshot of a simple test I wrote.  Unfortunately, the blog limits the types of files I can share, so I can’t share the actual script with you.

import java.io.*; import org.apache.commons.io.FileUtils; public class FileCompare extends FileCompareHelper { /** * Script Name : FileCompare * Description : Functional Test Script * @author Rational Tester */ public void testMain(Object[] args) { File file1 = new File("C:\\File1.txt"); File file2 = new File("C:\\File2.txt"); try { vpManual ("File_Compare_1", true, FileUtils.contentEquals (file1,file1)).performTest(); vpManual ("File_Compare_2", true, FileUtils.contentEquals (file1,file2)).performTest(); } catch (IOException ioe) {} } }

In the above, two verification points are created.  The first compares the first file to itself, which will always pass.  The second compares two different files, which results in a fail.

A logical next step would be to log the actual differences.  We’ll save that for a subsequent post, but for a quick fix, here is an article which shows some sample code that would get you started.

Advertisements

Responses

  1. Diff? 🙂

    Nice to find your blog though, I didn’t know you had one.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: