Testing a file upload

66 views
Skip to first unread message

Bob Silverberg

unread,
Sep 17, 2008, 1:52:44 PM9/17/08
to mxu...@googlegroups.com
I'm hoping that I'm just missing the obvious here, but I cannot figure
out how to write a unit test for a component that does a file upload
using cffile. Perhaps the answer is to simply not test the actual
cffile upload, but that seems kind of incomplete to me.

Any guidance would be greatly appreciated.

--
Bob Silverberg
www.silverwareconsulting.com

Marc Esher

unread,
Sep 17, 2008, 1:56:06 PM9/17/08
to mxu...@googlegroups.com
yeeeeesh.

is the problem when you use the plugin? if so, i think this is a tough
one to crack. Basically, it looks like the form scope isn't present
when you make webservice calls to a component, and that's why it
fails.

anyone else get around this?

marc

Peter Bell

unread,
Sep 17, 2008, 2:01:53 PM9/17/08
to mxu...@googlegroups.com
Hi Bob,

I'd have a component responsible for just the file upload and mock
that out. To me (FWIW), I'd say that testing the actual file upload is
an acceptance/functional test - not a unit test so I wouldn't do it
using a unit testing framework., Rather I'd test scenarios that
include that using Selenium or something similar as part of a set of
functional tests.

Best Wishes,
Peter

Bob Silverberg

unread,
Sep 17, 2008, 2:02:14 PM9/17/08
to mxu...@googlegroups.com
Actually I never even got that far. I was just trying to figure out
how to write the test. I don't know how to automate a form submission
of a file from within a test.

--
Bob Silverberg
www.silverwareconsulting.com

Peter Bell

unread,
Sep 17, 2008, 2:02:24 PM9/17/08
to mxu...@googlegroups.com
why would you want to?!

Just askin . . . :-)

Best Wishes,
Peter

Bob Silverberg

unread,
Sep 17, 2008, 2:05:34 PM9/17/08
to mxu...@googlegroups.com
Because I'm not into Selenium yet. It's on the list, but for now I'm
just trying to unit test as thoroughly as I can. I'd like to write a
complete test for my component, and one of its methods involves a file
upload, so ideally I'd like to be able to test that and receive a
pass/fail.

I did think that perhaps the solution was to NOT test the cffile
upload, and that may be what I end up having to do, but without the
extra selenium test I don't think that my testing of the component
would be complete.

What do you think?

--
Bob Silverberg
www.silverwareconsulting.com

Bob Silverberg

unread,
Sep 17, 2008, 2:07:34 PM9/17/08
to mxu...@googlegroups.com
One extra point. My component is the component that you describe,
Peter. It only interacts with the file system. It does uploads,
reads, writes, etc. I'd like to be able to unit test it, and then any
other component that needs that functionality would rely on this
component, and therefore could use a mock.

On Wed, Sep 17, 2008 at 2:05 PM, Bob Silverberg

--
Bob Silverberg
www.silverwareconsulting.com

Marc Esher

unread,
Sep 17, 2008, 2:09:48 PM9/17/08
to mxu...@googlegroups.com
what about using cfhttp from within your unit test? as long as you're
open to pulling out the big guns, that could work. of course, if you
have authentication, etc, you're hosed.

i'm with peter on this one: you already know that cffile action =
upload works. so you're probably trying to test something else...
where does the file go, all the junk around the cffile. so if you
abstract out the cffile... even if it's into a separate single-line
method ... then you can easily mock it, have your mock function record
data you want to record or whatever, etc.

On Wed, Sep 17, 2008 at 2:05 PM, Bob Silverberg

Peter Bell

unread,
Sep 17, 2008, 2:09:48 PM9/17/08
to mxu...@googlegroups.com
I'd argue that testing a file upload is outside of the scope of unit
testing which is why you're running into problems writing a unit test
for it (and would run into other problems running it as part of a
regression suite). I do think it'd be a great part of a functional
test though.

Bob Silverberg

unread,
Sep 17, 2008, 2:46:30 PM9/17/08
to mxu...@googlegroups.com
OK, you've both convinced me. I do get the fact that I shouldn't be
testing cffile itself, just my component's behaviour wrt it. I had an
inkling from the beginning that this was the answer. Although I'm
relatively new to this I think I'm already getting a feel for what
constitutes a valid test and what doesn't, and something definitely
felt fishy about this one.

Thanks guys!

--
Bob Silverberg
www.silverwareconsulting.com

Reply all
Reply to author
Forward
0 new messages