On 19 Jul 2013, at 19:53, Paul Robinson <[email protected]> wrote:

> I'm not sure if what you're after really is what TestUnit is good at. It 
> sounds more like you're after an integration test or possibly functional 
> test, but you're trying to get there with a unit test. Either break it out 
> into multiple independent unit tests, or use something else other than 
> TestUnit would be my call.

I don't really understand what you're getting at here Paul. Functional tests 
are written in test-unit (albeit with a test superclass that's provided by 
Rails). Functional tests are like mini integration tests (testing the 
integration of your controller action and your view layer).

Functional tests seem like a perfect fit for what Ian wanted to do.

On the multiple unit tests vs one functional test point, I let the size of the 
step into the unknown that I'm taking decide it for me.

In this case, I'd have known that I'd be sending CSV data and that I'd 
therefore have an HTTP header to check. I'd also have known that I'd need to 
get Rails to send my CSV data. Assuming I didn't have any programming to do in 
order to generate my CSV file, a simple test like the example I sent Ian is all 
I'd actually write in reality. This is because (knowing the domain I'd be 
working in fairly well) I could imagine where the code would go, and it would 
seem like a fairly small step to take.

If I didn't know the domain so well, or had to write some funky code to 
generate the CSV data itself, I'd probably go off and unit test the various 
moving parts (e.g. my own to_csv implementation), then come back and write the 
very same functional test I referred to earlier, to make sure the controller 
action did the right thing. Having just said that functional tests are like 
mini integeration tests for the controller/view interaction, they often give me 
a similar sized step into the unknown as a unit test. I use them to TDD my 
controller/view combination, and as such they feel very much like unit tests.

I put that dichotomy down to the power of the Rails macros; I have very little 
code to write when doing things like sending CSVs or rending HTML.

-- 
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nwrug-members.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to