# Testing batch programs

**URL:** <https://www.ruby-forum.com/t/testing-batch-programs/149861>\
**Category:** Rails\
**Created:** [September 30, 2008, 4:55pm UTC](https://www.ruby-forum.com/t/testing-batch-programs/149861 "2008-09-30T16:55:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonyfromky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e57/32.png) [@tonyfromky](https://www.ruby-forum.com/u/tonyfromky)\
**Post date:** [September 30, 2008, 4:55pm UTC](https://www.ruby-forum.com/t/testing-batch-programs/149861/1 "2008-09-30T16:55:55Z")

</div>

I have a batch program (yes, coders like me still exist) that, while  
it uses  
the same models are our web app, it isn’t webby at all. Basically, I  
grind  
through the database and send emails.

I changed the email delivery system and I want to write some testing  
code.

The test code I had written previously was terrible and no longer  
worked  
due to neglect and schedules.

So, what;s a good way to test a batch program? And end-to-end test  
(thank  
God for the test/mocks facility) will require that I use 6 or 7 tables  
and run  
through a lot of code that’s already been tested. Testing will  
consist of querying  
my mock emailer to see if it “sent” the right number of emails, etc.  
And then I  
can query tables to see if rows are properly modified. Blah.

On the other hand, the emailer has a fair number (50? 60?) of  
generally small  
methods that “can’t possibly” be wrong, so unit testing isn’t floating  
my boat.  
The methods typically wrap a ActiveModel.find or iterate over an  
array. Of  
course, if I was sure that these little perfect methods were being  
called  
properly I wouldn’t need to test!

So is there an alternative technique other than to just run a fake  
email delivery  
(did I mention the setup is a PITA?) and check the tables and mock  
emailer for  
expected values?
