Improving test performance by rendering less
I have for sometime had a feeling that functional and integration tests could be speed up even more by disabling the rendering of the layout within each test.
Here’s some sample code I used to remove layouts from all my integration and functional tests.
class ApplicationController
# remove layout to improve test time
def render_with_layout_disabled(*args)
args << {:layout => false} # force layout to always be false
render_without_layout_disabled(*args)
end
alias_method_chain :render, :layout_disabled
end
Tonight I’ve found that I get about 188% increase in integration test time and about 248% increase in functional test time by removing the layout.
Disabling the layout was pretty easy using alias_method_chain. My next question is does doing this break anything or make the test less meaningful? My thinking is no. Tests should be small in what they test. We can have a test to specifically test the layout of our application. Repeatedly testing the layout is redundant. So, making this change to my application for my tests seems like a good move.

I don’t know….
Disabling layouts for integration tests just feels wrong to me. I could understand the reasoning during functional testing because Rails really needs a de facto way to test the controller or the view.