From: Travis Whitton Date: 2003-01-17T02:22:16+09:00 Subject: Unit Testing in dynamic environments I'm just starting to get into unit testing, and I can already see how powerful a tool it can be to preemptively find bugs in my programs; however, a good portion of the classes I write revolve around databases and CGI. A lot of the methods implemented in these classes return highly variable results. Is there a way for me to leverge the benefits of unit testing when working with this type of data? Here's an excerpt of a typical class I might write: class DB def initialize() @lims = nil # LIMS system lims_connect end def lims_connect @lims = DBI.connect("DBI:Mysql:somedb", "someuser", "somepass") @lims.connected? end def get_pct_solids(sample_number) samp = sample_number.scan(/\d{6}/).to_s sql = "select SA_RESULT from sample where SA_SAMPNO = '#{samp}' and SA_ANAABB = '%SOLIDS' and (SA_STATUS = 'E' or SA_STATUS = 'F')" @lims.prepare(sql) do |sth| sth.execute if sth.rows > 0 last_pct_solids = sth.fetch.to_s.to_f last_pct_solids /= 100.0 # Must force float sth.finish return last_pct_solids else sth.finish return false end end end end Would there be a way to use unit test my get_pct_solids method, or is it only suited for environments where functions return predictable values? Thanks, Travis Whitton