unittest - what is the best way to reuse test data?
tjreedy at udel.edu
Wed Jun 3 12:40:51 EDT 2009
> I'm writing an application that needs to fetch a json file from a
> webserver. I'm writing the tests and have a question:
> if I have the following methods:
> def test_headers(self):
> headers = libary.get_data(data)
> check header status
With no json experience specifically....
Checking I/O is nasty since the test running correctly depends on
external resources running correctly and not just your program. I would
separate I/O tests from 'process the data' checks and do the latter with
canned data. If the canned data built into the test is the same as that
on the test server, then testing the fetch is an equality test.
> def test_get_info
> info = libary.get_info(libary.get_data(data))
> This way I call the url twice, even though I have the data available
> from the first test.
> my application would just variables such as:
> h = libary.get_data(data)
> i = libary.get_info(h)
> so only one call.
> What is the best way to set up tests to resuse the data more? I'm new to
> using the testing framework so I'm not sure on best practises and such.
> Is introducing persistance by using sql lite the best way? I should be
> able to just reuse data within the object. Or is my design wrong?
> Any tips or suggestions would be appreciated!
> - Mike
More information about the Python-list