[Activewarehouse-discuss] unit testing a control file

Thibaut Barrère thibaut.barrere at gmail.com
Tue Jul 17 18:55:58 EDT 2007


Hi,

here's my first and very raw (but quite successful) attempt at writing an
automated test for a real .ctl file, without requiring any modifications to
the .ctl file itself nor to AW-ETL.

The idea here is to mock the sources and destinations of a real .ctl file: I
replace all the sources by one mock source (eg: array of hashes), and
replace all the destinations by one, on which I assert to see if the
requirements are met. The connection to :etl_execution and the job creation
are also mocked, to avoid a database dependency and focus on the transforms.

With the plumbing removed, the test can be written:

describe "test.ctl" do
  it "should store :first_name + :last_name under :name" do
    load 'test.ctl', [ {:first_name => 'john',:last_name => 'barry'} ]
    @destination.should_receive(:write).with( { :first_name => 'john',
:last_name => 'barry', :name => 'john barry' } )
  end
end

This specification is written with RSpec and takes benefits of the mocking
abilities it provides (will be very practical to mock dimensions foreign-key
look-ups as well).
The plumbing was surprisingly easy to write, although it definitely requires
polishing (for instance, running two tests in a row won't work today!).
I think it would be reasonably easy to make AW-ETL more test-friendly by
refactoring some areas in order to remove part or all of the plumbing I
wrote to get this to work.

What do you think ?

cheers

Thibaut
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/activewarehouse-discuss/attachments/20070718/54355704/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.ctl
Type: application/octet-stream
Size: 221 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/activewarehouse-discuss/attachments/20070718/54355704/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: etl_spec.rb
Type: application/octet-stream
Size: 1435 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/activewarehouse-discuss/attachments/20070718/54355704/attachment-0001.obj 


More information about the Activewarehouse-discuss mailing list