Unit Testing for Sparx EA Scripts

      No Comments on Unit Testing for Sparx EA Scripts

Over the years I’ve created several scripts and script libraries to automate my work in Sparx EA, specially importing new data, and keeping that data in sync with the original source.

Because of my job/life there can often be months, between when I first start working on a script and when I get time to continue working on it. To make this easier on me, I decided to adopt a test driven approach to development, and create unit tests for my scripts so I can:

  • Make changes, re-run my tests to see if I broke something unintentionally.
  • Run tests to see what error I get to see where I left off making something new.
  • Run tests to see if anything has stopped working due to a version change in Sparx EA, or the script engine used by Sparx EA.

I do most of my API development directly in Sparx EA using the JScript. I like the structure of the JavaScript notation with the bonus ability to call ActiveX objects (like in VBScript). So years ago I found and modified jsUnity by Ates Goral to work under JScript.

To use, just download the zip file, it contains a text file with the script. If you’re at the point where you’re considering using Unit Tests, I’m assuming you’ll know how to create a new script in Sparx EA to copy the text in to.

For the rest, it works like any other implementation of jUnit, below is an example of a simple unit test to verify the basic functionality of the Index class that is part of my EARecordset library:

!INC EARecordset_unit_tests.jsUnity_modified
!INC EARecordset.EARecordset
function test_classIndex() 
	function testIndexCaseInsensitive()
		var local = {};
		local.o = EARecordset$.newIndex();	
		// the value should be "value2"
		jsUnity.assertions.assertEqual(local.o.get("KEY1",0),"value2","get('KEY1',0) = value2"); 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.