Arguments-Scope cached when only initializing a controller once in tests

34 views
Skip to first unread message

Steven Kelly

unread,
Apr 23, 2021, 3:14:16 AM4/23/21
to CFWheels
Hello again,

another weird potential bug I've found. This is about a controller test.
First, I placed the controller initialization in the packageSetup() function inside the test file. Implemented the first few tests, which went fine.

Then, a few tests later, my old tests suddenly failed. After some investigation, we figured out that arguments from other tests were passed to the same controller function. In the controller, we simply split the overview to _overview and overview as an example, _overview is a function that returns a struct and that's what we're testing. So when passing a filter as an argument in one test for example, it would pass that same filter to all consequent calls in the argument scope (even though other tests didn't pass those arguments at all).

We were really baffled about this for a while. In the end, it turns out what helped was to move the controller initialization to setup() instead, which runs before every test. Arguments no longer got cached from one test to another.

Now, onto the question… Is this a known bug, is it intended or is that an artifact of the cfwheels version we're using? Has anyone encountered this before?

Thanks,
Steven

Tom King

unread,
Apr 23, 2021, 3:52:40 AM4/23/21
to CFWheels
Which wheels version? 
T

Adam Chapman

unread,
Apr 25, 2021, 9:13:49 PM4/25/21
to CFWheels
The packageSetup() function is designed to only run once in the cfc in which it resides. If you are mutating values set in the packageSetup functions, they will persist in later tests.

I usually only use packageSetup for setting constant values OR any setup that is particularly resource intensive. 99 times out of 100, I use setup()

Hope this helps.

Steven Kelly

unread,
Apr 26, 2021, 4:50:01 AM4/26/21
to CFWheels
The cfwheels version we're using is  2.1.0. setup() will definitely be used over packageSetup() in the future. Thanks for the response so far.
Reply all
Reply to author
Forward
0 new messages