Best Practice - Integration Tests / Event Collection

Hello Guys,

Following on from a discussion yesterday whereby my use of explicitly setting FORM variables inside my tests was causing me issues, I wanted to get your opinions on best practices for setting variables in to the request collection.

Ideally, for every test case, my request context would be cleared, and only populated by calls and variables from that test method, as would happen in a real application with multiple requests. Imagine that each test is simulating a request.

I could explicitly clear the collection at the start of every test, but that seems like a great deal of redundant white-noise code. Albeit only one line. Perhaps I should be clearing the request collection on setUp() or tearDown()?

How do you guys pass FORM and URL variables into your event context for integration tests? and ensure they\re not carried through to the next test.

Thanks,

Robert

I would probably set them up in the setup if they are general for all
tests in the cfc. If not I use URL via a direct test

Hi Luis,

I’ve been playing this problem again this morning.

It seems that setting FORM and URL variables inside the individual tests is actually a bit of a problem. Because the tests are all run as part of a suite the variables in these scopes pollute across tests. So if In one of my tests I set FORM.Order_ID. Then that form variable exists, and is added to the request context for every test which is run after it as part of a suite.

This is bad as it means I have no isolation on the request and my tests are affected by one another.

As a temporary fix, in my own BaseTestCase I clear the FORM and URL scopes, which means they’re clean for every test.

I wonder if this is perhaps something we should consider adding into the coldbox core base tests?

Thanks,

Robert

what about setting them in the individual test ? Ahh, yes, I get you know. Well, I guess that it is the inherent nature of those scopes that they persist entirely for the request. So I am guessing, either clearing them manually in teardown() would be the best thing to provide isolation.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Thanks Luis,

That is exactly what I have done, clear those scopes on aetUp() and it works perfectly! :slight_smile:

My suggestion was, that perhaps the framework should be doing this for ms? As i wasn’t really aware that the scopes were persisting across tests and it’s caused quite a bit of confusion.

Robert

Not sure if the Framework should do it since the might be cases where
you want to keep it. I think it is w custom stuff. Maybe add it to the
docs

Hi Luis,

That's fair. I will add something in the docs about it.

On a side note related to testing, I started work on an implementation of Fixtures today.

Hopefully I'll have a rough draft ready before too long to play with.

Rob

Amazing. Been wanting to have time to add that to our testing
facilities. Love it.

Yeah it's not a easy nut to crack, I have deserialozation of XML, JSON and YAML all working to a standard format.

That format is now being deserialozed Into an array of ORM entities, but only simple properties and ID's at the moment.

The next step is relationships, which is somewhat more challenging :slight_smile:

Will keep you posted.

Robert